Complete the code to sort the DataFrame by the 'age' column in ascending order.
df_sorted = df.sort_values(by=[1])The sort_values() function sorts the DataFrame by the column name given in the by parameter. Here, we want to sort by 'age'.
Complete the code to sort the DataFrame by 'age' ascending and then by 'salary' descending.
df_sorted = df.sort_values(by=['age', [1]], ascending=[True, False])
by parameter.To sort by multiple columns, pass a list of column names to by. Here, we sort first by 'age' ascending, then by 'salary' descending.
Fix the error in the code to correctly sort by 'department' ascending and 'age' descending.
df_sorted = df.sort_values(by=['department', [1]], ascending=[True, False])
The second column to sort by is 'age' as specified. The code needs the correct column name in the list.
Fill both blanks to create a dictionary that sorts by 'age' ascending and 'salary' descending.
df_sorted = df.sort_values(by=[1], ascending=[2])
The by parameter takes a list of columns to sort by. The ascending parameter takes a list of booleans matching the order of columns.
Fill all three blanks to create a sorted DataFrame by 'department' ascending, 'age' descending, and 'salary' ascending.
df_sorted = df.sort_values(by=[[1], [2], [3]], ascending=[True, False, True])
by and ascending lists.The by list contains the columns in the order to sort. The ascending list matches the order with True or False for ascending or descending.