0

I have the following dataset.

enter image description here

I want to sort the dataset in such a way that the districts go in ascending order and for each district, it has to be sorted by date from 1982-01-01 to 2019-12-31.

For example:

DATE DISTRICT ...other features...
1982-01-01 Achham
--- ---
2019-12-31 Achham
--- ---
1982-01-01 Udaypur
--- ---
2019-12-31 Udaypur

How can I do this?

2 Answers2

0

You can use sort_values:

df = df.sort_values(by=['DATE','DISTRICT'])
Marcelo Paco
  • 2,732
  • 4
  • 9
  • 26
0

I found the answer.

df.sort_values(by=['DISTRICT', 'DATE'], ascending=[True, True], inplace=True)

It was simple.