I have a pandas DataFrame with two columns: toy and color. The color column includes missing values.
How do I fill the missing color values with the most frequent color for that particular toy?
Here's the code to create a sample dataset:
import pandas as pd
import numpy as np
df = pd.DataFrame({
'toy':['car'] * 4 + ['train'] * 5 + ['ball'] * 3 + ['truck'],
'color':['red', 'blue', 'blue', nan, 'green', nan,
'red', 'red', np, 'blue', 'red', nan, 'green']
})