EDIT: This question is not a clone of pandas dataframe replace nan values with average of columns because I want to replace the value of each column with th
You can try something like:
[df[col].fillna(df[col].mean(), inplace=True) for col in df.columns]
But that is just a way to do it. Your code is a priori almost correct. Your error is that you should call
train[value]
Instead of :
train['value']
Everywhere in your code. Because the latter will try to look for a column named as "value" which is rather a variable from a list you are iterating on.