0
0
Pandasdata~10 mins

Sorting by values 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 sort the DataFrame df by the column 'age' in ascending order.

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

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

Pandas
sorted_df = df.sort_values(by='score', ascending=[1])
Drag options to blanks, or click blank then click option'
ATrue
B'False'
C'True'
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the boolean value as a string instead of a boolean.
Setting ascending to True which sorts in ascending order.
3fill in blank
hard

Fix the error in the code to sort the DataFrame df by the column 'height'.

Pandas
sorted_df = df.sort_values(by=[1])
Drag options to blanks, or click blank then click option'
Aheight
B['height']
C'height'
Dheight'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the column name without quotes causing a NameError.
Using a list instead of a string when only one column is needed.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each word to its length only if the length is greater than 3.

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

Fill all three blanks to create a dictionary comprehension that maps each uppercase word to its score only if the score is greater than 50.

Pandas
result = { [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 word.lower() instead of word.upper().
Not filtering scores correctly.