Python Forum
sorting row values alphabetical
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sorting row values alphabetical
#1
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 :)
Reply
#2
If you're using pandas, the documentation states that you can use the "by" keyword argument to sort by a particular column.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Padlock of alphabetical strings Men 11 4,000 Aug-06-2022, 07:48 AM
Last Post: mariasmith1122
  Write a code to output in alphabetical order AbdelaliPython 1 4,607 Jan-19-2018, 09:03 PM
Last Post: j.crater

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020