0
0
Pandasdata~10 mins

Why sorting and ranking matter in Pandas - Test Your Understanding

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

Complete the code to sort the DataFrame by the 'score' column in ascending order.

Pandas
sorted_df = df.sort_values(by=[1])
Drag options to blanks, or click blank then click option'
A'score'
B'name'
C'age'
D'date'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a column name that doesn't exist in the DataFrame.
2fill in blank
medium

Complete the code to rank the 'score' column in descending order (highest score gets rank 1).

Pandas
df['rank'] = df['score'].rank(ascending=[1])
Drag options to blanks, or click blank then click option'
ATrue
BFalse
CNone
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Setting ascending=True which ranks lowest scores as 1.
3fill in blank
hard

Fix the error in the code to sort the DataFrame by 'age' in descending order.

Pandas
sorted_df = df.sort_values(by='age', [1]=False)
Drag options to blanks, or click blank then click option'
Adescend
Bascend
Cascending
Dorder
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names like 'ascend' or 'descend'.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.

Pandas
{word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Blen(word) > 3
Cword.startswith('a')
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as value instead of its length.
Wrong condition filtering.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their scores only if score is above 50.

Pandas
{ [1]: [2] for word, score in data.items() if [3] }
Drag options to blanks, or click blank then click option'
Aword.upper()
Bscore
Cscore > 50
Dword.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase words as keys.
Not filtering scores correctly.