I have a data frame of bank customer details and I have created a double indexed group by object grouped by income type and education returning the means of the actual income of those customers, I created an example below.
I'm looking to remap the mean income of this group by object back into the data frame to fill in NA values in the income column.
I can map with a single index but I'm not sure how to apply a doubled indexed map which provides a better assessment of averages. Any help is appreciated, thanks.
income_means = df.groupby(["income_type", "education"])['total_income'].agg('mean')
total_income
mean
income_type education
bachelors 50456
professional high-school 40657
elementary 30576
bachelors 55069
management high-school 50687
elementary 40687
df['total_income'] = df['total_income'].fillna(map(income_means))