I would like to reorder dataframe by student name. Does anybody have some suggestions?
df = pd.DataFrame({
'student': [
'monica', 'nathalia', 'anastasia', 'marina', 'ema'
],
'grade' : ['excellent', 'excellent', 'good', 'very good', 'good'
]
})
print (df)
student grade
0 monica excellent
1 nathalia excellent
2 anastasia good
3 marina very good
4 ema good
You can sort a dataframe using the sort_values method. Show activity on this post. df. sort_values(by=['contig', 'pos'], ascending=True) # where contig and pos are the column names.
Pre pandas 0.17:
# Sort by ascending student name
df.sort('student')
# reverse ascending
df.sort('student', ascending=False)
Pandas 0.17+ (as mentioned in the other answers):
# ascending
df.sort_values('student')
# reverse ascending
df.sort_values('student', ascending=False)
You can sort a dataframe using the sort_values
method.
df.sort_values('student')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With