Challenge - 5 Problems
Column Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of adding a new column with a calculation
What is the output DataFrame after running this code that adds a new column 'C' as the sum of columns 'A' and 'B'?
Data Analysis Python
import pandas as pd df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]}) df['C'] = df['A'] + df['B'] print(df)
Attempts:
2 left
💡 Hint
Adding columns can be done by simple arithmetic on existing columns.
✗ Incorrect
The new column 'C' is created by adding values from 'A' and 'B' element-wise, resulting in [5, 7, 9].
❓ data_output
intermediate2:00remaining
Result after removing a column using drop
What is the DataFrame output after dropping column 'B' from this DataFrame?
Data Analysis Python
import pandas as pd df = pd.DataFrame({'A': [10, 20], 'B': [30, 40], 'C': [50, 60]}) df2 = df.drop('B', axis=1) print(df2)
Attempts:
2 left
💡 Hint
drop with axis=1 removes columns.
✗ Incorrect
The drop method removes column 'B', leaving columns 'A' and 'C'.
🔧 Debug
advanced2:00remaining
Identify the error when removing a column
What error does this code raise when trying to remove a column 'D' that does not exist?
Data Analysis Python
import pandas as pd df = pd.DataFrame({'X': [1, 2], 'Y': [3, 4]}) df.drop('D', axis=1)
Attempts:
2 left
💡 Hint
Dropping a non-existing column without errors raises a specific exception.
✗ Incorrect
Pandas raises a KeyError when trying to drop a column that does not exist by default.
🚀 Application
advanced2:00remaining
Add a column based on condition from another column
Which option correctly adds a new column 'Status' that is 'High' if column 'Score' is above 50, otherwise 'Low'?
Data Analysis Python
import pandas as pd df = pd.DataFrame({'Score': [45, 55, 60, 30]})
Attempts:
2 left
💡 Hint
Use apply with a lambda for conditional assignment.
✗ Incorrect
Option D uses apply with a lambda function to assign 'High' or 'Low' based on the condition.
🧠 Conceptual
expert2:00remaining
Understanding inplace parameter effect when removing columns
What is the effect of using inplace=True in df.drop('A', axis=1, inplace=True)?
Attempts:
2 left
💡 Hint
inplace=True modifies the original DataFrame directly.
✗ Incorrect
With inplace=True, the original DataFrame is changed and the method returns None.