Challenge - 5 Problems
DataFrame Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this DataFrame creation?
Given the list of dictionaries, what will be the output DataFrame?
Pandas
import pandas as pd data = [{'name': 'Alice', 'age': 25}, {'name': 'Bob', 'age': 30}] df = pd.DataFrame(data) print(df)
Attempts:
2 left
💡 Hint
Each dictionary becomes a row; keys become columns.
✗ Incorrect
The DataFrame is created with columns 'name' and 'age'. Both dictionaries have these keys, so values fill the rows without missing data.
❓ data_output
intermediate1:30remaining
How many rows and columns does this DataFrame have?
What is the shape (rows, columns) of the DataFrame created from this list?
Pandas
import pandas as pd data = [{'x': 1, 'y': 2}, {'x': 3, 'z': 4}, {'y': 5, 'z': 6}] df = pd.DataFrame(data) print(df.shape)
Attempts:
2 left
💡 Hint
Count unique keys across all dictionaries for columns; count dictionaries for rows.
✗ Incorrect
There are 3 dictionaries (rows) and 3 unique keys ('x', 'y', 'z') making 3 columns.
🔧 Debug
advanced2:00remaining
What error does this code raise?
Identify the error raised by this code snippet:
Pandas
import pandas as pd data = [{'a': 1, 'b': 2}, {'a': 3, 'b': 4}] df = pd.DataFrame(data, columns=['a', 'c']) print(df)
Attempts:
2 left
💡 Hint
Check how pandas handles missing columns when specifying columns parameter.
✗ Incorrect
Pandas creates the DataFrame with columns 'a' and 'c'. Since 'c' is missing in data, its values are NaN.
🚀 Application
advanced2:30remaining
Which option creates a DataFrame with only keys 'name' and 'score'?
Given this list of dictionaries, which code creates a DataFrame with only 'name' and 'score' columns?
Pandas
data = [{'name': 'Anna', 'score': 90, 'age': 20}, {'name': 'Ben', 'score': 85, 'age': 22}]Attempts:
2 left
💡 Hint
Consider how each method selects or removes columns.
✗ Incorrect
All options produce a DataFrame with only 'name' and 'score' columns.
🧠 Conceptual
expert3:00remaining
What happens when dictionaries have nested dictionaries as values?
If you create a DataFrame from a list of dictionaries where some values are nested dictionaries, what is the type of those nested values in the DataFrame?
Pandas
import pandas as pd data = [{'id': 1, 'info': {'height': 170, 'weight': 65}}, {'id': 2, 'info': {'height': 180, 'weight': 75}}] df = pd.DataFrame(data) print(type(df.loc[0, 'info']))
Attempts:
2 left
💡 Hint
Think about how pandas stores complex objects inside cells.
✗ Incorrect
Pandas stores nested dictionaries as objects in cells, so the type remains dict.