0
0
Pandasdata~10 mins

Sorting by index 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 by its index in ascending order.

Pandas
df_sorted = df.[1](ascending=True)
Drag options to blanks, or click blank then click option'
Asort_values
Bsort_index
Corder_by
Darrange
Attempts:
3 left
💡 Hint
Common Mistakes
Using sort_values() instead of sort_index()
Trying to use order_by() which is not a pandas method
2fill in blank
medium

Complete the code to sort the DataFrame by its index in descending order.

Pandas
df_sorted = df.sort_index([1]=False)
Drag options to blanks, or click blank then click option'
Adescending
Breverse
Cascending
Dorder
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'descending' as a parameter name which does not exist
Using 'reverse' which is not a valid parameter here
3fill in blank
hard

Fix the error in the code to sort the DataFrame by index in place.

Pandas
df.sort_index(inplace=[1])
Drag options to blanks, or click blank then click option'
ATrue
B"True"
C1
Dyes
Attempts:
3 left
💡 Hint
Common Mistakes
Passing 'True' as a string instead of boolean True
Using 1 or 'yes' which are not valid boolean values here
4fill in blank
hard

Fill both blanks to sort the DataFrame by index in descending order and keep the result in a new variable.

Pandas
df_sorted = df.[1](ascending=[2])
Drag options to blanks, or click blank then click option'
Asort_index
Bsort_values
CFalse
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using sort_values instead of sort_index
Setting ascending to True which sorts ascending
5fill in blank
hard

Fill all three blanks to sort the DataFrame by index in ascending order, modify the original DataFrame, and return None.

Pandas
result = df.[1](ascending=[2], inplace=[3])
Drag options to blanks, or click blank then click option'
Asort_index
BTrue
Dsort_values
Attempts:
3 left
💡 Hint
Common Mistakes
Using sort_values instead of sort_index
Setting inplace to False which returns a new DataFrame
Passing strings instead of booleans for parameters