Skip to main contentSkip to solution

Arrange the following steps to perform a multi-column sort in pandas:

A. import pandas as pd

B. use .sort_values() with multiple columns and ascending parameter

C. load data into DataFrame

D. display the sorted DataFrame

Solution

✅ Correct Option: 1

A. Import pandas as pd, so that its functions are available.

C. Load the data into a DataFrame, for example with pd.read_csv()pd.read\_csv().

B. Use .sort_values() with a list of columns and the ascending parameter, for example df.sort_values(by=[′col1′,′col2′],ascending=[True,False])df.sort\_values(by=['col1', 'col2'], ascending=[True, False]).

D. Display the sorted DataFrame.


Option 4: the DataFrame cannot be created before pandas is imported.

Options 2 and 3: sorting cannot happen before the data is loaded.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question