Dropping by columns

Furthermore, we can also pass axis=1 to indicate a check for NaN by columns.

Check the following example:

dfx.dropna(how='all', axis=1)

And the output of the preceding code is as follows:

Note that store5 is dropped from the dataframe. By passing in axis=1, we are instructing pandas to drop columns if all the values in the column are NaN. Furthermore, we can also pass another argument, thresh, to specify a minimum number of NaNs that must exist before the column should be dropped:

dfx.dropna(thresh=5, axis=1)

And the output of the preceding code is as follows:

Compared to the preceding, note that even the store4 column is now dropped because it has more than five NaN values. 

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

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