0
0
Pandasdata~10 mins

head() and tail() for previewing in Pandas - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to show the first 5 rows of the DataFrame df.

Pandas
preview = df.[1]()
Drag options to blanks, or click blank then click option'
Ahead
Btail
Cshow
Dfirst
Attempts:
3 left
💡 Hint
Common Mistakes
Using tail() instead of head().
Trying to use show() which is not a pandas method.
2fill in blank
medium

Complete the code to display the last 3 rows of the DataFrame df.

Pandas
preview = df.[1](3)
Drag options to blanks, or click blank then click option'
Ahead
Bend
Clast
Dtail
Attempts:
3 left
💡 Hint
Common Mistakes
Using head(3) which shows the first 3 rows instead.
Trying to use last() which is not a pandas method.
3fill in blank
hard

Fix the error in the code to preview the first 10 rows of df.

Pandas
preview = df.[1](10)
Drag options to blanks, or click blank then click option'
Ahead
Bshow
Cpreview
Dtail
Attempts:
3 left
💡 Hint
Common Mistakes
Using tail(10) which shows the last 10 rows.
Using non-existent methods like show() or preview().
4fill in blank
hard

Fill all three blanks to create a dictionary showing the first 4 rows with their index and a column named 'score'.

Pandas
result = {df.[2]().index.[1]()[[3]]: df.[2]()['score'][[3]] for [3] in range(4)}
Drag options to blanks, or click blank then click option'
Atolist
Bhead
Ci
Dtail
Attempts:
3 left
💡 Hint
Common Mistakes
Using tail() instead of head().
Using j or other variable names instead of i.
Not converting index to list.
5fill in blank
hard

Fill all three blanks to create a dictionary of the last 3 rows with their index and 'age' column values.

Pandas
result = {df.[2]().index.[1]()[[3]]: df.[2]()['age'][[3]] for [3] in range(-3, 0)}
Drag options to blanks, or click blank then click option'
Atolist
Btail
Ci
Dhead
Attempts:
3 left
💡 Hint
Common Mistakes
Using head() instead of tail().
Using wrong loop range or variable.
Not converting index to list.