Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
tail() instead of head().Trying to use
show() which is not a pandas method.✗ Incorrect
The
head() method shows the first 5 rows by default.2fill in blank
mediumComplete 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'
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.✗ Incorrect
The
tail(n) method shows the last n rows of the DataFrame.3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
tail(10) which shows the last 10 rows.Using non-existent methods like
show() or preview().✗ Incorrect
To preview the first 10 rows, use
head(10). The other options are incorrect or invalid.4fill in blank
hardFill 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'
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.
✗ Incorrect
We convert the index to a list with
tolist(), use head() to get first rows, and iterate with i.5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
head() instead of tail().Using wrong loop range or variable.
Not converting index to list.
✗ Incorrect
Convert index to list with
tolist(), use tail() for last rows, and loop with i.