Complete the code to sort the MultiIndex DataFrame by its index.
sorted_df = df.[1]()The sort_index() method sorts a DataFrame by its index, which is needed for MultiIndex sorting.
Complete the code to sort the MultiIndex DataFrame by the second level of the index.
sorted_df = df.sort_index(level=[1])Index levels start at 0, so level 1 is the second level of the MultiIndex.
Fix the error in the code to sort the MultiIndex DataFrame in descending order.
sorted_df = df.sort_index(ascending=[1])To sort in descending order, set ascending=False.
Fill both blanks to sort the MultiIndex DataFrame by the first level in descending order.
sorted_df = df.sort_index(level=[1], ascending=[2])
Level 0 is the first index level, and ascending=False sorts descending.
Fill all three blanks to sort the MultiIndex DataFrame by both levels, first ascending then descending.
sorted_df = df.sort_index(level=[[1], [2]], ascending=[[3], False])
Sort by level 0 ascending (True), then level 1 descending (False).