Complete the code to sort the DataFrame by its index in ascending order.
df_sorted = df.[1]()The sort_index() method sorts the DataFrame by its index labels.
Complete the code to sort the DataFrame index in descending order.
df_sorted = df.sort_index([1]=False)
The ascending parameter controls the sort order. Setting it to True sorts ascending, False sorts descending.
Fix the error in the code to sort the DataFrame index in descending order.
df_sorted = df.sort_index(ascending=[1])To sort descending, set ascending=False as a boolean, not as a string or number.
Fill both blanks to sort the DataFrame index in descending order and reset the index.
df_sorted = df.sort_index([1]=False).[2](drop=True)
First, sort the index descending by setting ascending=False. Then reset the index with reset_index(drop=True) to get a clean integer index.
Fill both blanks to sort the DataFrame index in ascending order, keep the index, and select only rows where index is greater than 2.
df_filtered = df.sort_index([1]=True).loc[[2] > 2, :]
Sort ascending by setting ascending=True. Use df.index to filter rows where index > 2. Use : to select all columns.