How to sort and order a dataframe in Python?

744    Asked by ranjan_6399 in Data Science , Asked on Jan 15, 2020
Answered by Ranjana Admin

For sorting and ordering a dataframe, we need to create a dataframe.

import pandas as pd

df=pd.DataFrame({'col2':[444,555,666,444],'col3':['abc','def','ghi','xyz']})

df.head()



Now we sort and order the dataframe

df.sort_values(by='col2')





Your Answer

Interviews

Parent Categories