Challenge - 5 Problems
Pandas Import Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this code importing pandas?
Consider the following code snippet importing pandas and creating a DataFrame. What will be the output when printing
df.head()?Pandas
import pandas as pd data = {'Name': ['Anna', 'Bob', 'Cara'], 'Age': [28, 34, 29]} df = pd.DataFrame(data) print(df.head())
Attempts:
2 left
💡 Hint
Remember that
df.head() shows the first 5 rows with index and columns.✗ Incorrect
The pd.DataFrame creates a table with columns 'Name' and 'Age'. The head() method shows the first rows with their index starting at 0. The output includes the column headers and row indices.
❓ data_output
intermediate1:30remaining
What is the shape of the DataFrame after importing pandas and creating it?
Given this code, what is the shape (rows, columns) of the DataFrame
df?Pandas
import pandas as pd data = {'City': ['NY', 'LA', 'Chicago', 'Houston'], 'Population': [8.4, 4.0, 2.7, 2.3]} df = pd.DataFrame(data) print(df.shape)
Attempts:
2 left
💡 Hint
Shape shows (number of rows, number of columns).
✗ Incorrect
The dictionary has 4 cities, so 4 rows, and 2 keys, so 2 columns. The shape is (4, 2).
🔧 Debug
advanced1:00remaining
Which option causes an error when importing pandas?
Which of the following import statements will cause an error?
Attempts:
2 left
💡 Hint
Check the spelling of the library name.
✗ Incorrect
Option C uses 'panda' instead of 'pandas', which is not a valid module name and causes a ModuleNotFoundError.
🧠 Conceptual
advanced1:30remaining
Why do we use
import pandas as pd instead of just import pandas?What is the main reason for importing pandas with an alias like
pd?Attempts:
2 left
💡 Hint
Think about typing convenience and code readability.
✗ Incorrect
Using as pd creates a short alias so you can write pd.DataFrame() instead of pandas.DataFrame(), making code shorter and easier to read.
🚀 Application
expert1:30remaining
What is the output of this code using pandas import conventions?
Given the code below, what will be printed?
Pandas
import pandas as pd s = pd.Series([10, 20, 30], index=['a', 'b', 'c']) print(s['b'])
Attempts:
2 left
💡 Hint
Accessing a Series by index label returns the value at that label.
✗ Incorrect
The Series s has values 10, 20, 30 with labels 'a', 'b', 'c'. Accessing s['b'] returns 20.