0

I have a dataframe as follow:

df 

Col1     Col2
M1        4
M1        2
M1        1
M1        3
M2        3
M2        1
M2        2

I would like to sort the dataframe on python to achieve

Col1     Col2
M1        1
M1        2
M1        3
M1        4
M2        1
M2        2
M2        3

Any suggestion how to achieve this? Thank you

1
  • 1
    df.sort_values(['Col1','Col2'], inplace=True)? Commented Sep 26, 2019 at 0:06

1 Answer 1

0

Try

>>> df = df.sort_values(by=["Col1", "Col2"])
>>> print(df)

  Col1  Col2
2   M1     1
1   M1     2
3   M1     3
0   M1     4
5   M2     1
6   M2     2
4   M2     3
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.