Sort pandas-

 

# 2 kinds one is sorted by label value by one is

# Sort by label 
unsorted_df = pd.DataFrame (np.random.randn (10,2), index = [1,4,6,2,3,5,9,8,0,7], Columns = [ ' col2 ' , ' col1 ' ])
 Print (unsorted_df)
unsorted_df=unsorted_df.sort_index()
print (unsorted_df)

 

 

 

 

 

# Sorted by value 
sorted_df = pd.DataFrame ({ ' col1 ' : [2,1,1,1], ' col2 ' : [1,3,2,4 ]})
 Print (sorted_df)
sorted_df = sorted_df.sort_values(by='col1',kind='mergesort',ascending=True)
print (sorted_df)

 

 

Guess you like

Origin www.cnblogs.com/JinweiChang/p/12187595.html