0
0
Pandasdata~10 mins

Ascending and descending order 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='age', ascending=[1])
Drag options to blanks, or click blank then click option'
ATrue
B'yes'
CNone
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'False' instead of True for ascending order.
Passing a string instead of a boolean.
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'
AFalse
BTrue
C'descending'
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using True instead of False for descending order.
Passing a string instead of a boolean.
3fill in blank
hard

Fix the error in the code to sort df by 'height' in descending order.

Pandas
sorted_df = df.sort_values(by='height', ascending=[1])
Drag options to blanks, or click blank then click option'
A0
BFalse
C'False'
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using string 'False' instead of boolean False.
Passing None which defaults to ascending order.
4fill in blank
hard

Fill both blanks to sort df by 'age' ascending and then by 'score' descending.

Pandas
sorted_df = df.sort_values(by=[[1], [2]], ascending=[True, False])
Drag options to blanks, or click blank then click option'
A'age'
B'score'
C'height'
D'name'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the order of columns.
Using columns not present in the DataFrame.
5fill in blank
hard

Fill all three blanks to create a dictionary with word lengths for words longer than 3 characters.

Pandas
lengths = { [1] : len([2]) for [3] in words if len([2]) > 3 }
Drag options to blanks, or click blank then click option'
Aword
Ditem
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Using a variable name not defined in the comprehension.