Dropping missing values

One of the ways to handle missing values is to simply remove them from our dataset. We have seen that we can use the isnull() and notnull() functions from the pandas library to determine null values:

dfx.store4[dfx.store4.notnull()]

The output of the preceding code is as follows:

apple 20.0
watermelon 18.0
Name: store4, dtype: float64

The output shows that store4 only reported two items of data. Now, we can use the dropna() method to remove the rows:

dfx.store4.dropna()

The output of the preceding code is as follows:

apple 20.0
watermelon 18.0
Name: store4, dtype: float64

Note that the dropna() method just returns a copy of the dataframe by dropping the rows with NaN. The original dataframe is not changed.  

If dropna() is applied to the entire dataframe, then it will drop all the rows from the dataframe, because there is at least one NaN value in our dataframe:

dfx.dropna()

The output of the preceding code is an empty dataframe.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.159.82