Python Forum
sorting row values alphabetical - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: sorting row values alphabetical (/thread-15673.html)



sorting row values alphabetical - PolskaYBZ - Jan-27-2019

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 :)


RE: sorting row values alphabetical - stullis - Jan-27-2019

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