0

I apologize if the wording for this question is strange. I wasn't sure how to phrase it.

I have a python pandas data frame like this:

data = pd.DataFrame({"a":[1,4,5,4,2], "b":[1,1,2,1,1]})
a    b
1    1
3    1
5    2
4    1
2    1

I need to sort the data so that column b is descending, but for ties (all of the 1s in column b), values in column a are sorted ascending.

So it should look like this:

a   b
5   2
1   1
2   1
3   1
4   1

Any help is appreciated, thank you.

  • @QuangHoang that's a long comment considering your shortage of time. Backticks are not for emphasis btw, it's for code related things. –  Dec 01 '21 at 21:09

1 Answers1

-1

Use data.sort_values(by, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last', ignore_index=False, key=None)

jp1
  • 34
  • 3
  • It might benefit you to read [how to write a good answer](https://stackoverflow.com/help/how-to-answer). – BigBen Dec 01 '21 at 20:20