2

I'd like to sort kst column in descending order.

df.sort_values(by=['kst'], ascending=False)

Even though I put the above code, it doesn't works and result is following.

           kst            test  test
 0    2018-07-08 10:00    2a    8
 1    2018-07-08 09:30    2e    6
 2    2018-07-08 09:00    32    3
 3    2018-07-08 08:30    r2    2
 4    2018-07-08 08:00    f2    4
 5    2018-07-08 07:30    w2    6
 6    2018-07-08 07:00    s2    7
 7    2018-07-08 06:30    e2    5
 8    2018-07-08 06:00    e2    2

How can I sort kst column in descending order?

2
  • 4
    Looks sorted to me... Commented Jul 8, 2018 at 2:57
  • 1
    df=df.sort_values(by=['kst'], ascending=False) assign it back Commented Jul 8, 2018 at 3:39

2 Answers 2

1

The kst column is already sorted based on time in that column...what else do u want to sort based on kst ? if u want to sort other columns ,then i suggest u to specify the exact column name you want to sort like example , df.sort_values(by=['test'], ascending=False).

Sign up to request clarification or add additional context in comments.

2 Comments

As you said, the kst column is already sorted in ascending order. But I'd like to sort kst column in descending orde NOT ascending order. Your suggested code doesn't woks. It means kst colume is still ascending order.
The sort of kst column already seem to be in descending order (highest time first and then reducing to lowest time). What am I missing?
1

There is a switch for that: inplace= True, see the manual

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.