I'm currently working on a machine learning project where I have to replace -99 values (nan) with the means of each column. However, I cannot manage to replace the correct values, only the first across all columns. So, what I need is to have the mean each column instead than the -99 of that column.
I produce the means for each column first:
mean_miss = []
for i in df_train[vars_ind_numeric]:
mean_miss = df_train[vars_ind_numeric].mean()
then pass:
for var in df_train[vars_ind_numeric]:
df_train[vars_ind_numeric]=df_train[vars_ind_numeric]\
.replace(nan, mean_miss[var])
Any idea on how to fix this? thanks in advance