I have a dataframe with zip codes and incomes. Some of the incomes are = 0, which is wrong.
I have a dictionary with each zip code mapped to the mean income for all incomes within that zip code.
I want to replace all of the incomes in my dataframe that = 0 with the mean income value for it's respective zip code.
I have tried this:
income = []
for row in df['income']:
if row == 0:
income.replace({0:{income_zip}}, inplace = True)
else:
income.append(row)
To no avail. I have found lots of resources to replace all 0's with the same value, I am just unsure how to replace a 0 with a variable value from a dict based on another value in the row.