Python Forum

Full Version: Dataframe Rows Sorting
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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)