Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Sorting of DataFrame and Series

Shulou Source: shulou.com Published: 2022-06-03 04:48:15 09月16日 Update

For more information on big data's analysis and modeling, please follow the official account "bigdatamodeling".

# # sorting # # from pandas import DataFrame, Series# Series sorts by index the sort_index method returns the new object obj = Series ([1,3,2,5,6] Index=list ('dabce')) obj.sort_index () obj.sort_index (ascending=False) # Series sort by value sort_values method returns a new object obj.sort_values () obj.sort_values (ascending=False) # DataFrame sort by index / column index # default axis=0, row index sort # axis=1, column index sort frame = DataFrame (np.random.randn (4,3), columns=list ('dbe'), index= [' Ut', 'Oh',' Tex', 'Ore']) frame.sort_index () # same as frame.sort_index (axis=0) frame.sort_index (ascending=False) frame.sort_index (axis=1) frame.sort_index (axis=1) Ascending=False) # DataFrame sorts frame = DataFrame by column ({'averse: [1,3,1,5],' baked: [2,1,4,6]}) # sort method but only applies to python2frame.sort (columns= ['averse,' b'], ascending= [True, True]) frame.sort (columns= ['ajar,' b'], ascending= [True, False]) # sort_index method frame.sort_index (by= ['ajar,' b'] Ascending= [True, True]) frame.sort_index (by= ['averse,' b'], ascending= [True, False]) # sort_values method frame.sort_values (by= ['ajar,' b'], ascending= [True, True]) frame.sort_values (by= ['averse,' b'], ascending= [True, False])

Tags: Sort method index object list public content data data analysis more analysis Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Xiaomi Redmi Shulou Tech Info NVidia