Dropping Rows and Columns with Missing Values
Learn how to drop rows and columns with missing values in a Pandas DataFrame.
We'll cover the following
The dropna
function
In the previous lesson, we learned how to check the number of missing values in a column or row. The next step is to handle them. We essentially have two options for handling missing values. First, we can drop rows or columns that contain missing values. The dropna
function is used to drop rows and columns with missing values. To use this function accurately and efficiently, we need to first learn its parameters.
The axis
parameter determines if rows or columns with missing values are removed. The default value is zero, which indicates rows. The how
parameter takes one of two values: any
or all
. The default value is any
, which drops a row or column with at least one missing value. If all
is selected, all values must be missing for a row or column to be dropped. Let’s look at some examples to understand how these parameters are used. We’ll create the DataFrame
in the image below for the following examples.
Get hands-on with 1400+ tech skills courses.