Use df.fillna(df.mean()) directly to fill all zero with a mean
If you want to fill the zero value with the average value of this column, you can use this
suppose x=df['Item_Weight'] here Item_Weight is the name of the column
here we assign (fill zero values x with the average value x in x)
df['Item_Weight'] = df['Item_Weight'].fillna((df['Item_Weight'].mean()))
If you want to fill the null value with some string, use
here Outlet_size is the column name
df.Outlet_Size = df.Outlet_Size.fillna('Missing')
Sunny Barnwal Jun 27 '18 at 22:19 2018-06-27 22:19
source share