Missing Values
This lesson will elaborate on how to deal with data that has missing values.
Missing values
During data collection and entry, it is possible that some values are missed, or data was not available for some entries. Hence, missing data is very common among data science applications.
Pandas makes it very easy to work with missing data. It does not include missing values in all of its different calculations such as sum, mean, etc. by default.
Pandas writes the value NaN
(Not a Number) when it finds a missing value.
Detecting missing values
We can detect missing values using the function isnull
. It returns True
wherever there is a missing value, and False
, otherwise.
Press + to interact
import pandas as pddf = pd.read_csv('housing.csv')# check which columns have how many missing valuesprint("Missing values in every column : \n" ,df.isnull().sum())print("\n\n Missing values total : ",df.isnull().sum().sum())# Display rows that have missing valuesmissing = df['total_bedrooms'].isnull()print(df[missing])
In line 5, we use the function isnull
and then use sum
on it. This gives us a ...
Access this course and 1400+ top-rated courses and projects.