Handling Missing Values
Introduction
Welcome to our Handling Missing Values lesson. Missing values in data sheets can complicate data analysis. Incorrect handling can lead to inaccurate results. So, we'll learn how to manage these values using Python's Pandas.
Missing Data in Datasets
Missing data in datasets is common. It occurs when no data values are stored for certain variable observations. It can cause bias, make some functions inapplicable, and obscure insightful data patterns. Consider a dataset of student scores:
"Charlie" has a missing score (None).
Identifying Missing Values with Pandas
Before handling missing values, we must identify them. Pandas' functions isnull() and notnull() can perform this task. isnull() returns a DataFrame where each cell is either True or False depending on that cell's null status.
From our student scores data:
The None (missing) value for "Charlie" returns True when isnull() is used. notnull works similarly, but returns exactly opposite values: True is for present value!:
Handling Missing Values: Removal, Part 1
After identifying missing values, the next step is handling them. The strategy depends on the nature of our data and analysis purpose. A common strategy is to remove rows with None values using the dropna() function:
"Charlie"'s row is removed because it contained a null value. Also the one row with a missing name is removed.
Handling Missing Values: Removal, Part 2
