Challenge - 5 Problems
Drop Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output after dropping rows by index
What is the output DataFrame after dropping rows with index 1 and 3?
Pandas
import pandas as pd df = pd.DataFrame({ 'A': [10, 20, 30, 40, 50], 'B': [5, 4, 3, 2, 1] }) result = df.drop([1, 3]) print(result)
Attempts:
2 left
💡 Hint
Use df.drop() with a list of row indices to remove those rows.
✗ Incorrect
The drop method removes rows with index 1 and 3. Remaining rows are 0, 2, and 4.
❓ data_output
intermediate2:00remaining
Resulting DataFrame after dropping columns
What is the resulting DataFrame after dropping columns 'X' and 'Z'?
Pandas
import pandas as pd df = pd.DataFrame({ 'X': [1, 2, 3], 'Y': [4, 5, 6], 'Z': [7, 8, 9] }) result = df.drop(columns=['X', 'Z']) print(result)
Attempts:
2 left
💡 Hint
Use df.drop() with columns parameter to remove columns.
✗ Incorrect
Dropping columns 'X' and 'Z' leaves only column 'Y'.
🔧 Debug
advanced2:00remaining
Identify the error when dropping rows
What error will this code raise?
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3]})
result = df.drop(5)
print(result)
Pandas
import pandas as pd df = pd.DataFrame({'A': [1, 2, 3]}) result = df.drop(5) print(result)
Attempts:
2 left
💡 Hint
Check if the index 5 exists in the DataFrame before dropping.
✗ Incorrect
Index 5 does not exist in the DataFrame index, so drop raises a KeyError.
🚀 Application
advanced2:00remaining
Drop rows with missing values
Given this DataFrame, which code correctly drops all rows that have any missing (NaN) values?
Pandas
import pandas as pd import numpy as np df = pd.DataFrame({ 'A': [1, 2, np.nan, 4], 'B': [np.nan, 2, 3, 4] })
Attempts:
2 left
💡 Hint
Use dropna() to remove rows with missing values.
✗ Incorrect
dropna() removes rows with any NaN values. axis=1 drops columns, not rows.
🧠 Conceptual
expert2:00remaining
Effect of inplace parameter in drop method
What is the effect of using inplace=True in the drop method on a DataFrame?
Attempts:
2 left
💡 Hint
inplace=True changes the original DataFrame directly.
✗ Incorrect
When inplace=True, drop modifies the original DataFrame and returns None.