While creating a DataFrame or importing a CSV file, there could be some NaN values in the cells. NaN values mean "Not a Number" which generally means that there are some missing values in the cell. To deal with this type of data, you can either remove the particular row (if the number of missing values is low) or you can handle these values.
To replace the Nan values with zeroes we will use a DataFrame.replace() method.
pandas.DataFrame.replace() Method
The DataFrame.replace() method in Pandas is a simple method that takes two parameters, first is the value of the string, list, dictionary, etc which has to be replaced. Secondly, it takes the value with which our data has to be replaced.
Syntax:
DataFrame.replace(
to_replace=None,
value=NoDefault.no_default,
inplace=False,
limit=None,
regex=False,
method=NoDefault.no_default
)
To work with Python Pandas, we need to import the pandas library. Below is the syntax,
import pandas as pd
Let us understand with the help of an example.
Output:

need an explanation for this answer? contact us directly to get an explanation for this answer