Replace NaN Values with Zeros in Pandas DataFrame

In data science, you will usually have missing data . You have a couple of alternatives to work with missing data.
  1. Drop the whole row
  2. Fill the row-column combination with some value
It would not make sense to drop the row/column as that would throw away that metric for all rows. So, let's look at how to replace NaN values by Zeroes/some other values in a column/row of a Pandas Dataframe. Either use fillna() or replace() will do this for you: Replace NaN Values with Zeros in a Pandas DataFrame using fillna() :
df.fillna(0)
Replace NaN Values with Zeros in a Pandas DataFrame using replace() :
df.replace(np.nan, 0, inplace=True)
Replace NaN Values with Zeros for a single column using fillna() :
df['Column'] = df['Column'].fillna(0)
Replace NaN Values with Zeros for a single column using replace() :
df['Column'] = df['Column'].replace(np.nan, 0)
Replace NA values with mode of a DataFrame column
df['column'].fillna(df['column'].mode()[0], inplace=True)
Replace NA values with mean of a DataFrame column
df['column'].fillna((df['column'].mean()), inplace=True)