0
0
Pandasdata~10 mins

Detecting missing values with isna() in Pandas - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Detecting missing values with isna()
Start with DataFrame
Call isna() method
Check each cell for missing value
Return DataFrame of True/False
Use result to find or handle missing data
We start with a DataFrame, call isna() to check each cell for missing values, and get back a DataFrame showing True where data is missing and False otherwise.
Execution Sample
Pandas
import pandas as pd

data = {'A': [1, None, 3], 'B': [4, 5, None]}
df = pd.DataFrame(data)
missing = df.isna()
print(missing)
This code creates a DataFrame with some missing values and uses isna() to detect them, printing a DataFrame of True/False.
Execution Table
StepDataFrame CellValueisna() ResultExplanation
1df['A'][0]1FalseValue is 1, not missing
2df['A'][1]NoneTrueValue is None, missing detected
3df['A'][2]3FalseValue is 3, not missing
4df['B'][0]4FalseValue is 4, not missing
5df['B'][1]5FalseValue is 5, not missing
6df['B'][2]NoneTrueValue is None, missing detected
7End--All cells checked, isna() returns DataFrame of True/False
💡 All cells checked, isna() returns DataFrame showing True where values are missing.
Variable Tracker
VariableStartAfter isna() call
df{'A':[1,None,3],'B':[4,5,None]}Same DataFrame, unchanged
missingNot defined{'A':[False,True,False],'B':[False,False,True]}
Key Moments - 2 Insights
Why does isna() return True for None values?
Because None represents missing data in pandas, isna() detects it and returns True as shown in rows 2 and 6 of the execution_table.
Does isna() change the original DataFrame?
No, isna() returns a new DataFrame of booleans without modifying the original, as shown in variable_tracker where df stays the same.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the isna() result for df['B'][1]?
ATrue
BFalse
CNone
DError
💡 Hint
Check row 5 in the execution_table where df['B'][1] is 5 and isna() returns False.
At which step does isna() detect the first missing value?
AStep 1
BStep 4
CStep 2
DStep 6
💡 Hint
Look at execution_table row 2 where df['A'][1] is None and isna() returns True.
If the DataFrame had no None values, what would the missing DataFrame contain?
AAll False
BAll True
CMixed True and False
DError
💡 Hint
Refer to variable_tracker and execution_table showing True only where values are None.
Concept Snapshot
pandas.DataFrame.isna() detects missing values.
Returns a DataFrame of booleans: True if missing, False if not.
Does not change original data.
Use to find or filter missing data easily.
Full Transcript
We start with a pandas DataFrame containing some missing values represented by None. Calling the isna() method checks each cell and returns a new DataFrame of the same shape with True where values are missing and False otherwise. This helps us quickly see where data is missing without changing the original DataFrame. For example, in the sample code, isna() returns True for cells with None and False for others. This method is useful for detecting missing data before cleaning or analysis.