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

后端 未结 13 1402
无人共我
无人共我 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:10

    If you were to convert it to a pandas dataframe, you can also accomplish this by using fillna.

    import numpy as np
    df=np.array([[1,2,3, np.nan]])
    
    import pandas as pd
    df=pd.DataFrame(df)
    df.fillna(0)
    

    This will return the following:

         0    1    2   3
    0  1.0  2.0  3.0 NaN
    >>> df.fillna(0)
         0    1    2    3
    0  1.0  2.0  3.0  0.0
    
    0 讨论(0)
提交回复
热议问题