Python Forum

Full Version: sorting row values alphabetical
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I have the below dataframe object in which I would like to sort the rows in alphabetical order.


Output:
flights ORG_AIR DEST_AIR 0 LAX SLC 1 DEN IAD 2 DFW VPS 3 DFW DCA 4 LAX MCI 5 IAH SAN
The textbook gives the below answer, which I understand.
flights_sort = flights.apply(sorted, axis=1)
I would however like to know for myself if there is a possibility if this is as well possible via the .sort_values() method. I tried every combination, but unfortunately I am not able to figure it out.

Thanks :)
If you're using pandas, the documentation states that you can use the "by" keyword argument to sort by a particular column.