Challenge - 5 Problems
Dropna Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of dropna() on rows with any missing values
What is the output DataFrame after running the code below?
Pandas
import pandas as pd df = pd.DataFrame({ 'A': [1, 2, None, 4], 'B': [None, 2, 3, 4], 'C': [1, 2, 3, 4] }) result = df.dropna() print(result)
Attempts:
2 left
💡 Hint
dropna() removes rows with any missing values by default.
✗ Incorrect
The dropna() method removes rows where any column has a missing value. Only rows 1 and 3 have no missing values.
❓ data_output
intermediate1:30remaining
Number of rows after dropping columns with missing values
Given the DataFrame below, how many rows remain after dropping columns with any missing values?
Pandas
import pandas as pd df = pd.DataFrame({ 'X': [1, 2, 3, 4], 'Y': [None, 2, None, 4], 'Z': [1, 2, 3, 4] }) result = df.dropna(axis=1) print(len(result))
Attempts:
2 left
💡 Hint
dropna(axis=1) removes columns with missing values, not rows.
✗ Incorrect
Column 'Y' has missing values and is dropped. Columns 'X' and 'Z' remain with all 4 rows.
🔧 Debug
advanced1:30remaining
Error raised by dropna() with invalid parameter
What error does the following code raise?
Pandas
import pandas as pd df = pd.DataFrame({'A': [1, None, 3]}) result = df.dropna(axis=2) print(result)
Attempts:
2 left
💡 Hint
Valid axis values for DataFrame are 0 or 1.
✗ Incorrect
The axis parameter must be 0 (rows) or 1 (columns). Using 2 causes a ValueError.
🚀 Application
advanced2:00remaining
Using dropna() to keep rows with at least 2 non-missing values
Which code correctly drops rows that have less than 2 non-missing values?
Attempts:
2 left
💡 Hint
The thresh parameter sets the minimum number of non-NA values required to keep a row.
✗ Incorrect
thresh=2 keeps rows with at least 2 non-missing values. min_count is not a dropna parameter.
🧠 Conceptual
expert2:30remaining
Effect of dropna() with subset parameter on DataFrame
Given the DataFrame below, what is the output after running df.dropna(subset=['B', 'C'])?
Pandas
import pandas as pd df = pd.DataFrame({ 'A': [1, 2, 3, 4], 'B': [None, 2, None, 4], 'C': [1, None, 3, 4] }) result = df.dropna(subset=['B', 'C']) print(result)
Attempts:
2 left
💡 Hint
dropna with subset only checks specified columns for missing values.
✗ Incorrect
Rows 0, 1, and 2 have missing values in columns B or C, so only row 3 remains.