Fill Missing Scores

Each record has name and score. A missing score is represented by None (null in the examples). Replace missing scores with replacement using Pandas and return all rows as a list of dictionaries with name and score. Preserve row order and existing scores, including zero. Empty input returns an empty list.

Difficulty: beginner

Show hint

Build a DataFrame with the two named columns, call fillna({"score": replacement}), then to_dict(orient="records").

Examples

  • [[{"name":"Asha","score":null},{"name":"Ben","score":80}],50][{"name":"Asha","score":50},{"name":"Ben","score":80}]

Your solution

Python · Pandas

Results

Python and Pandas load when you Run or Submit. Return a Python list, dictionary or scalar as requested.

Back to Lesson