Skip to content

Instantly share code, notes, and snippets.

@AayushSameerShah
Created May 23, 2021 06:17
Show Gist options
  • Save AayushSameerShah/d00397ebd114d013bb124735dccc3bf2 to your computer and use it in GitHub Desktop.
Save AayushSameerShah/d00397ebd114d013bb124735dccc3bf2 to your computer and use it in GitHub Desktop.
This snippet will give you an idea on how to sort values when it is in the group
'''
State District Population(values)
Guj Kutch 30
Ahmedabad 100
Surat 50
Vadodra 20
Jak 10
Maha Mumbai 130
Borri 10
Pune 150
UP Patna 20
Gorakhpur 50
Luckhnow 500
'''
# Having this... if we need to sort in the group itself...
DF.sort_values()
# ↑ This will scramble all values
## THIS IS THE ONE ↓ ##
DF.sort_values().sort_index(index= 0, sort_remaining= False)
# ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
# This part is so useful - Do it!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment