0
0
Pandasdata~10 mins

sort_index() for index sorting 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]()
Drag options to blanks, or click blank then click option'
Asort_index
Bsort_values
Csort
Dorder
Attempts:
3 left
💡 Hint
Common Mistakes
Using sort_values() instead of sort_index()
Using sort() which is deprecated
Trying to use order() which is not a pandas method
2fill in blank
medium

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

Pandas
df_sorted = df.sort_index([1]=False)
Drag options to blanks, or click blank then click option'
Aascending
Bdescending
Creverse
Dorder
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'descending' parameter which does not exist
Using 'reverse' parameter which is invalid
Confusing parameter names
3fill in blank
hard

Fix the error in the code to sort the DataFrame index in descending order.

Pandas
df_sorted = df.sort_index(ascending=[1])
Drag options to blanks, or click blank then click option'
A'False'
BTrue
CFalse
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Passing 'False' as a string instead of boolean
Passing 0 which is interpreted differently
Using True which sorts ascending
4fill in blank
hard

Fill both blanks to sort the DataFrame index in descending order and reset the index.

Pandas
df_sorted = df.sort_index([1]=False).[2](drop=True)
Drag options to blanks, or click blank then click option'
Aascending
Breset_index
Csort_values
Dsort_index
Attempts:
3 left
💡 Hint
Common Mistakes
Using sort_values instead of reset_index
Not setting drop=True when resetting index
Using ascending=True which sorts ascending
5fill in blank
hard

Fill both blanks to sort the DataFrame index in ascending order, keep the index, and select only rows where index is greater than 2.

Pandas
df_filtered = df.sort_index([1]=True).loc[[2] > 2, :]
Drag options to blanks, or click blank then click option'
Aascending
Bdf.index
C:
Dindex
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'index' instead of 'df.index' for filtering
Using False for ascending which sorts descending
Not selecting columns properly