← All Python interview questions

Fill missing product ratings the defensible way

EasyPandas — CleaningAmazonNykaa

A ratings export has gaps. The analytics lead wants missing ratings filled with the median rating of that product's category, not a global constant.

Write fill_ratings(df) that returns a copy of the DataFrame with the rating column filled that way, rounded to 2 decimals. The original DataFrame must not change.