March 2020
Beginner to intermediate
352 pages
8h 40m
English
We can use the fillna() method to replace NaN values with any particular values.
Check the following example:
filledDf = dfx.fillna(0)filledDf
The output of the preceding code is shown in the following screenshot:

Note that in the preceding dataframe, all the NaN values are replaced by 0. Replacing the values with 0 will affect several statistics including mean, sum, and median.
Check the difference in the following two examples:
dfx.mean()
And the output of the preceding code is as follows:
store1 20.0store2 21.0store3 22.0store4 19.0store5 NaNdtype: float64
Now, let's compute the mean from the filled dataframe ...
Read now
Unlock full access