pandas fillna not working

后端 未结 3 1211
甜味超标
甜味超标 2020-11-30 10:35

I have a dataframe with nans in it:

>>>df.head()
Out[1]: 
            JPM US SMALLER COMPANIES C ACC
1990-01-02                             NaN
1990         


        
相关标签:
3条回答
  • 2020-11-30 10:38

    you need inplace

    df[1].fillna(0, inplace=True)
    
    0 讨论(0)
  • 2020-11-30 10:43

    You need to assign the value df = df.fillna( t )

    0 讨论(0)
  • 2020-11-30 11:02

    You have two options:

    1) Specific for each column

    cols_fillna = ['column1','column2','column3']
    # replace 'NaN' with zero in these columns
     for col in cols_fillna:
         df[col].fillna(0,inplace=True)
         df[col].fillna(0,inplace=True)
    

    2) For the entire dataframe

    df = df.fillna(0)
    
    0 讨论(0)
提交回复
热议问题