How to replace NaN values by Zeroes in a column of a Pandas Dataframe?

后端 未结 13 1773
无人共我
无人共我 2020-11-22 01:37

I have a Pandas Dataframe as below:

      itm Date                  Amount 
67    420 2012-09-30 00:00:00   65211
68    421 2012-09-09 00:00:00   29424
69             


        
13条回答
  •  情书的邮戳
    2020-11-22 02:04

    Easy way to fill the missing values:-

    filling string columns: when string columns have missing values and NaN values.

    df['string column name'].fillna(df['string column name'].mode().values[0], inplace = True)
    

    filling numeric columns: when the numeric columns have missing values and NaN values.

    df['numeric column name'].fillna(df['numeric column name'].mean(), inplace = True)
    

    filling NaN with zero:

    df['column name'].fillna(0, inplace = True)
    

提交回复
热议问题