Challenge - 5 Problems
Column Creator Master
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 arithmetic operation
What is the output DataFrame after running this code?
Pandas
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 element-wise sums the values in each row.
✗ Incorrect
The new column 'C' is created by adding columns 'A' and 'B' element-wise, resulting in [5, 7, 9].
❓ data_output
intermediate2:00remaining
Result of creating a column with a constant value
What is the DataFrame output after adding a new column 'D' with a constant value 10?
Pandas
import pandas as pd df = pd.DataFrame({'X': [7, 8, 9]}) df['D'] = 10 print(df)
Attempts:
2 left
💡 Hint
Assigning a single value to a new column repeats it for all rows.
✗ Incorrect
The new column 'D' is filled with the constant value 10 for every row.
🔧 Debug
advanced2:00remaining
Identify the error when creating a new column with a list of wrong length
What error does this code raise?
Pandas
import pandas as pd df = pd.DataFrame({'A': [1, 2, 3]}) df['B'] = [4, 5] print(df)
Attempts:
2 left
💡 Hint
The list assigned must match the number of rows exactly.
✗ Incorrect
Assigning a list of length 2 to a DataFrame with 3 rows causes a ValueError due to length mismatch.
🚀 Application
advanced2:00remaining
Create a new column based on condition from existing column
Given a DataFrame with column 'score', which option creates a new column 'passed' that is True if score >= 50, else False?
Pandas
import pandas as pd df = pd.DataFrame({'score': [45, 55, 60, 30]})
Attempts:
2 left
💡 Hint
Use comparison operator >= to include 50 as passing.
✗ Incorrect
The condition 'score >= 50' correctly marks scores 50 and above as True for passing.
❓ visualization
expert3:00remaining
Visualize the effect of creating a new column with a function
Which option shows the correct bar chart after creating a new column 'length' with the length of strings in column 'words'?
Pandas
import pandas as pd import matplotlib.pyplot as plt df = pd.DataFrame({'words': ['apple', 'banana', 'pear']}) df['length'] = df['words'].apply(len) df.plot.bar(x='words', y='length') plt.show()
Attempts:
2 left
💡 Hint
The length of 'apple' is 5, 'banana' is 6, 'pear' is 4.
✗ Incorrect
Applying len to each string creates the 'length' column with correct values, shown as bars in the chart.