AnalystPath

Median Reading From a Frequency Table

PandasHardSenior level~10 min

Problem

You are given a DataFrame `reading` with two integer columns: `value` (a sensor reading, the primary key) and `occurs` (how many times that value was recorded). Imagine expanding the table so each `value` appears `occurs` times. Report the **median** of that whole expanded list, rounded to one decimal place, in a single column named `median`.

For example, if `value` 0 occurs 7 times and `value` 1 occurs 1 time, the expanded list is seven 0s and one 1 (eight values); the median is the average of the 4th and 5th values, both 0, so 0.0.

Input data

Example rows — the live problem includes the full dataset.

reading
valueoccurs
07
11

Expected output

Your answer should return 1 row with the columns median.

Starter code (Pandas (Python))

import pandas as pd

def median_reading_from_a_frequency_table(reading) -> pd.DataFrame:
    # Your code here
    return reading

Solve this Pandas question free

Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related Pandas questions