Fixed issue where pandas.DataFrame.fillna failed to populate Nan

  • 2021-01-25 07:42:06
  • OfStack

If alone is


>>> df.fillna(0)
>>> print(df) #  You can see that nothing has changed 
 
 
>>> print(df.fillna(0)) #  If you print directly you'll see that it's filled in 
>>> print(df) #  But if you print it again, it's gone. Again Nan

If you print it again, you will find that it is not filled at all. This is because the inplace parameter is not added.

1 It is important to add inplace = True as an argument so that the source data can be changed and saved.


>>> df.fillna(0, inplace = True)
>>> print(df) # You can see the change 
 

Related articles: