The fillna() method in Pandas
In this exercise, we are using the datasource employeeswithna.csv. You can download the datasource and use for the transformation.
The fillna() method is used to fill the NaN/null values in the Series/DataFrame to some other value.
Syntax a) pandas.Series.fillna(value=None)
b) pandas.DataFrame.fillna(value=None)
Example: Load the Dataframe.
Python
import pandas as pd mydata=pd.read_csv("employeeswithna.csv") mydata
The output of the above code is shown below:
Let’s load the NaN/null values with the value 0.
Python
mydata.fillna(0)
The output of the above code is shown below: