Replace NaN Values with Zeros in Pandas DataFrame

import pandas as pd

df = pd.DataFrame({'values_1': [700, np.nan, 500, np.nan],
                   'values_2': [np.nan, 150, np.nan, 400] 
                   })
df = df.fillna(0)

print(df)

  values_1  values_2
0     700.0       0.0
1       0.0     150.0
2     500.0       0.0
3       0.0     400.0

References:

  • 1 Replace NaN Values with Zeros in Pandas DataFrame
Previous
Next