-2

What is the best way to replace all the null "NaN" values in a Python dataframe with the value 0?

Also, is it possible to do this with a for loop?

  • 2
    Does this answer your question? [How to replace NaN values by Zeroes in a column of a Pandas Dataframe?](https://stackoverflow.com/questions/13295735/how-to-replace-nan-values-by-zeroes-in-a-column-of-a-pandas-dataframe) – Pranav Hosangadi Nov 12 '20 at 15:30
  • ```df.fillna(0)```. And Welcome to Stackoverflow. Make sure to read the guideline on how to post questions. Also, make sure to have made an honest attempt at solving the issue yourself. – Serge de Gosson de Varennes Nov 12 '20 at 15:34

1 Answers1

2

you can simply use

df.fillna(0)
Ironkey
  • 2,568
  • 1
  • 8
  • 30