简体   繁体   中英

How to sort each row in a dataframe from the smallest to largest number

I have a dataframe that I would like each row to be sorted from smallest to largest numbers and still remain in the same row and the same numbers but just sorted out. Here a example I have below.

[ https://i.stack.imgur.com/IrRIJ.png]

As you can see in the image is that each row has numbers that are not in order.

I would like my result to be something like this.

[ https://i.stack.imgur.com/BDIRL.png]

Generally you can do this:

df1 = df.apply(lambda x: sorted(x), axis=1)

But in your example, it seems that each rows has a different number of items (4, 6, 4), which doesn't make sense.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM