Interview Query

Rain on Rainy Days

Have you seen this question before?

You’re given a dataframe df_rain containing rainfall data. The dataframe has two columns: day of the week and rainfall in inches.

Write a function median_rainfall to find the median amount of rainfall for the days on which it rained.

Note: You may assume it rained on at least one of the days.


import pandas as pd

rainfall = {"Day" : ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"], "Inches" : [0, 1.2, 0, 0.8, 1]}

df_rain = pd.DataFrame(rainfall)


def median_rainfall(df_rain) -> 1
Next question: Email Marketing System
Python 3.9.6
Loading editor
Use Shift + Enter to run code