I'm looking To fill Nan population values for specific states/values for column State in my date Frame using jupiter notebooks.
Code:
DataGroupby = pd.DataFrame(Data.groupby(['State'])['Population'].mean())
DataGroupby = DataGroupby.reset_index()
DataGroupby.head(30)
DataChangePop = Data.loc[(Data['Population'].isnull() == True)]
Wisconsinmean = float((DataGroupby.loc[DataGroupby['State'] == 'Wisconsin','Population'].values)[0])
print(Wisconsinmean)
(Data.loc[Data['State'] == 'Wisconsin', 'Population']).fillna(Wisconsinmean ,inplace = True)
for x in DataGroupby['State']:
Data.loc[Data['State'] == x,'Population'].fillna(value = (DataGroupby.loc[DataGroupby['State'] == x,'Population'].values)[0], axis = 0,inplace = True)
I didn't try much but I expect the values that were Nan in Population to be the mean of the corresponding State i selected but the values are still Nan.