import pandas as pd
person = {
"first": ["Kushagra", "Jane", "John","Adam","Eve"],
"last": ["Gupta", "Doe", "Doe","Doe","Damm"],
"email": ["Kushagra225@gmail.com", "JaneDoe123@gmail.com", "John@gmail.com","Adam@gmail.com","Eve@gmail.com"],
"salary":[72000,60000,50000,100000,80000]
}
df = pd.DataFrame(person)
df
#sorting ascending
df.sort_values(by='last')
#sorting descending
df.sort_values(by='last', ascending=False)
#sorting by multiple columns
df.sort_values(by=['last','first'], ascending=False)
#sorting last name with ascending and first name with descending order
df.sort_values(by=['last','first'], ascending=[True,False])
#saving the changes in original df
df.sort_values(by=['last','first'], ascending=[True,False], inplace=True)
df
#sorting based on index using sort_index method
df = df.sort_index()
df
#sorting series objects
df['last'].sort_values()
#top 3 salary
df['salary'].nlargest(3)
#top 3 salary with details
df.nlargest(3,'salary')
#bottom 3 salary with details
df.nsmallest(3,'salary')