Two Columns, Two Guesses

Machine Learning in CodeMedium+10 XP+10

Two Columns, Two Guesses

A shop's daily table has gaps in two columns, and each needs a different guess.

  • A missing price is just unrecorded, so use the median of the known prices.
  • A missing sales count means the shop sold nothing that day, so fill it with the constant 0.

Task: write fill_shop_table(prices, sales). Both are lists with None for gaps. Each list has at least one real number.

  • Use one SimpleImputer(strategy="median") for the prices.
  • Use another SimpleImputer(strategy="constant", fill_value=0) for the sales.
  • Return {"price": filled prices, "sales": filled sales}, every value rounded to 2 decimal places.

Examples

prices = [2.5, None, 3.0, 2.0, 40.0]
sales = [12, None, 9, None, 3]
returns {'price': [2.5, 2.75, 3.0, 2.0, 40.0], 'sales': [12.0, 0.0, 9.0, 0.0, 3.0]}
prices = [None, 1.0, 1.0, 4.0]
sales = [5, 6, 7, 8]
returns {'price': [1.0, 1.0, 1.0, 4.0], 'sales': [5.0, 6.0, 7.0, 8.0]}

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run