0
0
Pandasdata~10 mins

rank() method and ranking methods 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 rank the values in the 'score' column of the DataFrame.

Pandas
df['rank'] = df['score'].[1]()
Drag options to blanks, or click blank then click option'
Asort
Brank
Cindex
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using sort() instead of rank()
Using index() which does not rank values
2fill in blank
medium

Complete the code to rank the 'score' column with method 'min' to assign the minimum rank to ties.

Pandas
df['rank_min'] = df['score'].rank(method=[1])
Drag options to blanks, or click blank then click option'
A'first'
B'average'
C'max'
D'min'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'average' which assigns average ranks to ties
Using 'max' which assigns maximum ranks to ties
3fill in blank
hard

Fix the error in the code to rank the 'score' column in descending order.

Pandas
df['rank_desc'] = df['score'].rank(ascending=[1])
Drag options to blanks, or click blank then click option'
AFalse
B'False'
CTrue
D'True'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'False' as a string instead of boolean False
Using True which ranks ascending
4fill in blank
hard

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

Pandas
{word: df['score'].rank(method=[1])[i] for i, word in enumerate(words) if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
A'average'
B>
C<
D'min'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in the condition
Using 'min' instead of 'average' for method
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their ranks where rank is greater than 2.

Pandas
{word[1]: df['score'].rank(method=[2])[i] for i, word in enumerate(words) if df['score'].rank(method=[3])[i] > 2}
Drag options to blanks, or click blank then click option'
A.upper()
B'average'
C'min'
D'max'
Attempts:
3 left
💡 Hint
Common Mistakes
Not uppercasing the word
Using the same method for both blanks incorrectly