Bird
Raised Fist0
Data Analysis Pythondata~20 mins

Identifying missing values (isnull, isna) in Data Analysis Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Missing Values Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of isnull() on a DataFrame
What is the output of the following code snippet?
Data Analysis Python
import pandas as pd
import numpy as np
df = pd.DataFrame({
    'A': [1, np.nan, 3],
    'B': [np.nan, 2, 3]
})
result = df.isnull()
print(result)
A
       A      B
0  False   True
1   True  False
2  False  False
B
       A      B
0  False   True
1   True   True
2  False  False
C
       A      B
0  False  False
1   True   True
2  False  False
D
       A      B
0   True  False
1  False   True
2  False  False
Attempts:
2 left
💡 Hint
Remember that isnull() returns True where values are missing (NaN).
❓ data_output
intermediate
2:00remaining
Counting missing values with isna()
What is the output of this code that counts missing values per column?
Data Analysis Python
import pandas as pd
import numpy as np
df = pd.DataFrame({
    'X': [np.nan, 1, 2, np.nan],
    'Y': [3, 4, np.nan, 6]
})
missing_counts = df.isna().sum()
print(missing_counts)
A
X    2
Y    1
dtype: int64
B
X    1
Y    2
dtype: int64
C
X    0
Y    0
dtype: int64
D
X    2
Y    2
dtype: int64
Attempts:
2 left
💡 Hint
Count how many NaN values appear in each column.
🔧 Debug
advanced
2:00remaining
Identify the error in using isnull() on a list
What error will this code raise?
Data Analysis Python
import pandas as pd
values = [1, None, 3]
result = values.isnull()
print(result)
ANo error, prints [False, True, False]
BTypeError: isnull() missing 1 required positional argument
CAttributeError: 'list' object has no attribute 'isnull'
DValueError: Cannot convert list to DataFrame
Attempts:
2 left
💡 Hint
Check if the list type supports isnull() method.
🚀 Application
advanced
2:00remaining
Filter rows with missing values using isna()
Which code snippet correctly filters rows with any missing values in DataFrame df?
Data Analysis Python
import pandas as pd
import numpy as np
df = pd.DataFrame({
    'A': [1, np.nan, 3],
    'B': [4, 5, np.nan]
})
Adf[df.isna().all(axis=0)]
Bdf[df.isna().any(axis=1)]
Cdf[df.isna().any(axis=0)]
Ddf[df.isna().all(axis=1)]
Attempts:
2 left
💡 Hint
Use isna() with any() along rows to find rows with missing values.
🧠 Conceptual
expert
2:00remaining
Difference between isnull() and isna() in pandas
Which statement best describes the difference between pandas isnull() and isna() methods?
Aisnull() detects missing values, isna() detects empty strings.
Bisnull() detects only None values, while isna() detects only NaN values.
Cisnull() works only on DataFrames, isna() works only on Series.
DThey are exactly the same; both detect missing values identically.
Attempts:
2 left
💡 Hint
Check pandas documentation for isnull() and isna() methods.

Practice

(1/5)
1. What do the isnull() and isna() functions do in pandas?
easy
A. They identify missing or empty values in a DataFrame or Series.
B. They fill missing values with zeros.
C. They remove rows with missing values.
D. They convert data types to numeric.

Solution

  1. Step 1: Understand the purpose of isnull() and isna()

    Both functions check for missing data and return True where data is missing.
  2. Step 2: Differentiate from other functions

    They do not fill, remove, or convert data but only detect missing values.
  3. Final Answer:

    They identify missing or empty values in a DataFrame or Series. -> Option A
  4. Quick Check:

    Missing data detection = C [OK]
Hint: Think: True means missing, False means present [OK]
Common Mistakes:
  • Confusing detection with filling missing values
  • Thinking they remove data instead of marking it
  • Assuming they change data types
2. Which of the following is the correct way to check for missing values in a pandas DataFrame named df?
easy
A. df.isempty()
B. df.checknull()
C. df.isnull()
D. df.missing()

Solution

  1. Step 1: Recall pandas function names for missing data

    The correct pandas function to detect missing values is isnull().
  2. Step 2: Verify other options

    Functions like checknull(), missing(), and isempty() do not exist in pandas for this purpose.
  3. Final Answer:

    df.isnull() -> Option C
  4. Quick Check:

    Correct pandas method = D [OK]
Hint: Remember: pandas uses isnull() or isna() [OK]
Common Mistakes:
  • Using non-existent function names
  • Confusing with methods that fill or drop data
  • Misspelling function names
3. Given the following code, what is the output?
import pandas as pd
data = {'A': [1, None, 3], 'B': [4, 5, None]}
df = pd.DataFrame(data)
print(df.isna())
medium
A. A DataFrame with all False values.
B. A DataFrame showing True where values are missing and False otherwise.
C. A DataFrame with all True values.
D. An error because isna() is not a valid function.

Solution

  1. Step 1: Understand the input DataFrame

    The DataFrame has missing values at df['A'][1] and df['B'][2].
  2. Step 2: Apply isna() method

    This method returns True at missing positions and False elsewhere.
  3. Final Answer:

    A DataFrame showing True where values are missing and False otherwise. -> Option B
  4. Quick Check:

    Missing spots = True, others = False [OK]
Hint: Look for None or NaN spots turning True [OK]
Common Mistakes:
  • Thinking isna() fills missing values
  • Expecting all True or all False output
  • Confusing isna() with dropna()
4. What is wrong with this code snippet to detect missing values?
import pandas as pd
data = {'X': [10, 20, None]}
df = pd.DataFrame(data)
print(df.isnull)
medium
A. The variable name df is invalid.
B. The DataFrame is not created correctly.
C. The isnull function does not exist in pandas.
D. The code is missing parentheses after isnull to call the function.

Solution

  1. Step 1: Check the usage of isnull

    isnull is a function and needs parentheses to execute, like df.isnull().
  2. Step 2: Verify other parts of the code

    DataFrame creation and variable names are correct; isnull exists in pandas.
  3. Final Answer:

    The code is missing parentheses after isnull to call the function. -> Option D
  4. Quick Check:

    Function call needs () = A [OK]
Hint: Remember to add () to call functions [OK]
Common Mistakes:
  • Forgetting parentheses on function calls
  • Assuming isnull is an attribute, not a method
  • Misnaming variables or functions
5. You have a DataFrame df with columns ['Name', 'Age', 'Score']. Some Age and Score values are missing. How do you create a new column 'MissingCount' that counts how many missing values each row has?
hard
A. df['MissingCount'] = df.isnull().sum(axis=1)
B. df['MissingCount'] = df.isnull().sum()
C. df['MissingCount'] = df.isnull().count(axis=1)
D. df['MissingCount'] = df.isnull().mean(axis=1)

Solution

  1. Step 1: Use isnull() to detect missing values

    This returns True/False for each cell indicating missing data.
  2. Step 2: Sum missing values per row with sum(axis=1)

    Summing True values (counted as 1) across columns gives missing count per row.
  3. Final Answer:

    df['MissingCount'] = df.isnull().sum(axis=1) -> Option A
  4. Quick Check:

    Sum True per row = B [OK]
Hint: Sum isnull() across columns with axis=1 [OK]
Common Mistakes:
  • Summing without axis=1 sums all missing in DataFrame
  • Using count() instead of sum() to count missing
  • Using mean() which gives fraction, not count
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard