Interview Query

Impute Median

Have you seen this question before?

You’re given a dataframe df_cheeses containing a list of the price of various cheeses from California. The dataframe has missing values in the price column.

Write a function cheese_median to impute the median price of the selected California cheeses in place of the missing values. You may assume at least one cheese is not missing its price.



import pandas as pd

cheeses = {"Name": ["Bohemian Goat", "Central Coast Bleu", "Cowgirl Mozzarella", "Cypress Grove Cheddar", "Oakdale Colby"], "Price" : [15.00, None, 30.00, None, 45.00]}

df_cheeses = pd.DataFrame(cheeses)


Name Price
Bohemian Goat 15.00
Central Coast Bleu 30.00
Cowgirl Mozzarella 30.00
Cypress Grove Cheddar 30.00
Oakdale Colby 45.00
Next question: K Nearest Entries
Python 3.9.6
Loading editor
Use Shift + Enter to run code