Replacing the Missing Values

Learn how to replace the missing values in a Pandas DataFrame.

We'll cover the following

The fillna function

In the previous lesson, we saw how to drop rows and columns that contain missing values. Dropping may not be the best option in many cases, though. Another option for handling missing values is to replace them with an actual value with the fillna function.

The value to be used as a replacement for missing values depend on the characteristics of the data. We may choose to replace missing values with the average value of the column or the most frequent value in the column. We will be creating the following DataFrame to do the examples. Let’s start with replacing the missing value in column A with the average value of this column.

Get hands-on with 1200+ tech skills courses.