0
0
Pandasdata~10 mins

nlargest() and nsmallest() 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 get the 3 largest values from the 'score' column.

Pandas
top_scores = df['score'].[1](3)
Drag options to blanks, or click blank then click option'
Ansmallest
Bsort_values
Cnlargest
Dhead
Attempts:
3 left
💡 Hint
Common Mistakes
Using nsmallest() instead of nlargest()
Using sort_values() without specifying ascending=False
2fill in blank
medium

Complete the code to get the 2 smallest values from the 'age' column.

Pandas
youngest = df['age'].[1](2)
Drag options to blanks, or click blank then click option'
Ansmallest
Bnlargest
Csort_values
Dtail
Attempts:
3 left
💡 Hint
Common Mistakes
Using nlargest() instead of nsmallest()
Using tail() which returns last rows, not smallest values
3fill in blank
hard

Fix the error in the code to get the 4 largest values from the 'height' column.

Pandas
tallest = df.[1]('height', 4)
Drag options to blanks, or click blank then click option'
Ahead
Bnsmallest
Csort_values
Dnlargest
Attempts:
3 left
💡 Hint
Common Mistakes
Calling nlargest() on a Series instead of DataFrame with column name
Using sort_values() without specifying ascending=False
4fill in blank
hard

Fill both blanks to get the 5 smallest values from the 'weight' column.

Pandas
lightest = df.[1](5, '[2]')
Drag options to blanks, or click blank then click option'
Ansmallest
Bnlargest
Cweight
Dheight
Attempts:
3 left
💡 Hint
Common Mistakes
Using nlargest() instead of nsmallest()
Using wrong column name
5fill in blank
hard

Fill all three blanks to create a dictionary of top 3 tallest people's names and heights.

Pandas
top_tallest = {person: height for person, height in zip(df['[1]'][df['[2]'].[3](3).index], df['[2]'].[3](3))}
Drag options to blanks, or click blank then click option'
Aname
Bheight
Cnlargest
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong column names
Using nsmallest() instead of nlargest()