Challenge - 5 Problems
Preview Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of head() with n=3?
Given the DataFrame below, what will
df.head(3) return?Pandas
import pandas as pd data = {'Name': ['Anna', 'Bob', 'Cathy', 'David', 'Eva'], 'Age': [23, 35, 45, 28, 32]} df = pd.DataFrame(data) print(df.head(3))
Attempts:
2 left
💡 Hint
head(n) shows the first n rows of the DataFrame.
✗ Incorrect
The head(3) method returns the first 3 rows of the DataFrame, which are rows with index 0, 1, and 2.
❓ Predict Output
intermediate2:00remaining
What does tail() return by default?
Given the DataFrame below, what will
df.tail() return?Pandas
import pandas as pd data = {'City': ['NY', 'LA', 'Chicago', 'Houston', 'Phoenix'], 'Population': [8.4, 4.0, 2.7, 2.3, 1.7]} df = pd.DataFrame(data) print(df.tail())
Attempts:
2 left
💡 Hint
tail() without argument returns the last 5 rows by default.
✗ Incorrect
The DataFrame has 5 rows total. tail() returns the last 5 rows by default, which is the entire DataFrame here.
❓ data_output
advanced2:00remaining
How many rows does df.head(0) return?
Consider the DataFrame below. What is the number of rows in
df.head(0)?Pandas
import pandas as pd data = {'Product': ['A', 'B', 'C', 'D'], 'Price': [10, 20, 30, 40]} df = pd.DataFrame(data) print(len(df.head(0)))
Attempts:
2 left
💡 Hint
head(0) means show zero rows from the top.
✗ Incorrect
head(0) returns an empty DataFrame with zero rows but same columns.
❓ Predict Output
advanced2:00remaining
What is the output of df.tail(2) on a 6-row DataFrame?
Given the DataFrame below, what will
df.tail(2) output?Pandas
import pandas as pd data = {'Letter': ['a', 'b', 'c', 'd', 'e', 'f'], 'Number': [1, 2, 3, 4, 5, 6]} df = pd.DataFrame(data) print(df.tail(2))
Attempts:
2 left
💡 Hint
tail(2) returns the last two rows.
✗ Incorrect
The last two rows have index 4 and 5 with letters 'e' and 'f'.
🧠 Conceptual
expert2:00remaining
Which statement about head() and tail() is TRUE?
Select the correct statement about
head() and tail() methods in pandas.Attempts:
2 left
💡 Hint
Think about what 'head' and 'tail' mean in everyday life.
✗ Incorrect
head(n) returns the first n rows, like the start of a list. tail(n) returns the last n rows, like the end of a list.