Challenge - 5 Problems
Shape Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
Output of shape attribute on DataFrame
What is the output of the following code snippet?
Pandas
import pandas as pd df = pd.DataFrame({ 'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9] }) print(df.shape)
Attempts:
2 left
💡 Hint
The shape attribute returns a tuple with (rows, columns).
✗ Incorrect
The DataFrame has 3 rows and 3 columns, so df.shape returns (3, 3).
❓ data_output
intermediate1:30remaining
Shape of a Series object
What is the output of the shape attribute for the following pandas Series?
Pandas
import pandas as pd s = pd.Series([10, 20, 30, 40]) print(s.shape)
Attempts:
2 left
💡 Hint
Series shape is a tuple with one element representing length.
✗ Incorrect
A pandas Series is one-dimensional, so its shape is a tuple with one element: (4,).
🔧 Debug
advanced1:30remaining
Error when accessing shape of a list
What error will this code produce?
Pandas
my_list = [1, 2, 3, 4] print(my_list.shape)
Attempts:
2 left
💡 Hint
Lists in Python do not have a shape attribute.
✗ Incorrect
Python lists do not have a shape attribute, so trying to access it raises an AttributeError.
🧠 Conceptual
advanced2:00remaining
Understanding shape for 3D numpy arrays
If a numpy array has shape (4, 3, 2), what does each number represent?
Attempts:
2 left
💡 Hint
Shape is given as (layers, rows, columns) for 3D arrays.
✗ Incorrect
For a 3D numpy array, the shape is (layers, rows, columns). So (4, 3, 2) means 4 layers, each with 3 rows and 2 columns.
🚀 Application
expert2:00remaining
Determining shape after DataFrame filtering
Given the DataFrame below, what is the shape after filtering rows where 'Age' > 30?
Pandas
import pandas as pd data = {'Name': ['Anna', 'Bob', 'Cara', 'Dave'], 'Age': [25, 35, 45, 28], 'City': ['NY', 'LA', 'NY', 'SF']} df = pd.DataFrame(data) filtered_df = df[df['Age'] > 30] print(filtered_df.shape)
Attempts:
2 left
💡 Hint
Count how many rows have Age greater than 30 and remember columns stay the same.
✗ Incorrect
Only 'Bob' and 'Cara' have Age > 30, so 2 rows remain. The DataFrame has 3 columns, so shape is (2, 3).