Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dataframe Rows Sorting
#1
How to sort dataframe rows horizontally from lowest to the highest
for an example I have
This To This
1 3 2 8 5 -->1 2 3 5 8
3 2 4 8 6 -->2 3 4 6 8
2 6 3 7 9 -->2 3 6 7 9
5 3 7 9 6 -->3 5 6 7 9
7 2 4 8 6 -->2 4 6 7 8
2 6 5 7 9 -->2 5 6 7 9
|
|
20000 lines long.
Thanx.
Reply
#2
You can do this easily using numpy, e.g.

import numpy as np
import pandas as pd
result = np.sort(your_dataframe.values, axis=1)
sorted_dataframe = pd.DataFrame(result)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pandas Dataframe Filtering based on rows mvdlm 0 1,396 Apr-02-2022, 06:39 PM
Last Post: mvdlm
  change dataframe header with 2 rows tonycat 2 1,963 Oct-29-2020, 01:41 AM
Last Post: tonycat
  How to add a few empty rows into a pandas dataframe python_newbie09 2 16,280 Sep-20-2019, 08:52 AM
Last Post: python_newbie09
  reindex dataframe after sorting Clunk_Head 4 4,665 Jun-26-2019, 01:04 AM
Last Post: scidam
  Write specific rows from pandas dataframe to csv file pradeepkumarbe 3 5,425 Oct-18-2018, 09:33 PM
Last Post: volcano63
  Add rows in dataframe arya_starc 1 2,346 Oct-03-2018, 08:02 AM
Last Post: volcano63
  Get rows with same value from dataframe of particular columns angelwings 1 2,708 Apr-11-2018, 02:40 AM
Last Post: scidam
  Dropping rows in a dataframe sobrio1 0 2,602 Dec-03-2017, 11:15 PM
Last Post: sobrio1
  Stack dataframe columns into rows klllmmm 0 3,007 Sep-03-2017, 02:26 AM
Last Post: klllmmm

Forum Jump:

User Panel Messages

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