dataframe 按照指定顺序排序

Posted ~小疯子~

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了dataframe 按照指定顺序排序相关的知识,希望对你有一定的参考价值。

如下index 按照区间排序  ['0_5', '6_9','10_14', '15_19',  '20_29',  '30_49', '50_99', '100_199', '200_299', '300_399','400_1000']

abcdefgh
0_50.058360.277910.389130.052820.046250.001620.023430.06217
100_1990.056870.269010.364380.060240.049720.001490.029460.07987
10_140.055470.273480.396200.052520.044690.001690.024130.06581
15_190.056980.270870.398040.052510.044170.001330.023240.06679
200_2990.058400.255210.358030.063780.052520.001670.031520.08889
20_290.055440.272260.394790.052640.044860.001640.024170.06892
300_3990.059790.241890.357840.065970.053650.001510.030690.09904
30_490.056540.273530.386340.053400.045550.001570.024360.06994
400_10000.056010.231320.358050.067630.057340.001440.032050.10433
50_990.057570.274370.372330.056030.047710.001620.026540.07371
6_90.055330.274380.398550.052370.045360.001770.02272

0.06442

 一行代码就可以了,  如果要在列中对某一列排序,可以把那一列设置为index , 然后在排序, 很方便


sort_list = ['0_5', '6_9','10_14', '15_19',  '20_29',  '30_49', '50_99', '100_199', '200_299', '300_399','400_1000']
dd = dd.loc[sort_list]
abcdefgh
0_50.058360.277910.389130.052820.046250.001620.023430.06217
6_90.055330.274380.398550.052370.045360.001770.022720.06442
10_140.055470.273480.396200.052520.044690.001690.024130.06581
15_190.056980.270870.398040.052510.044170.001330.023240.06679
20_290.055440.272260.394790.052640.044860.001640.024170.06892
30_490.056540.273530.386340.053400.045550.001570.024360.06994
50_990.057570.274370.372330.056030.047710.001620.026540.07371
100_1990.056870.269010.364380.060240.049720.001490.029460.07987
200_2990.058400.255210.358030.063780.052520.001670.031520.08889
300_3990.059790.241890.357840.065970.053650.001510.030690.09904
400_10000.056010.231320.358050.067630.057340.001440.032050.10433

以上是关于dataframe 按照指定顺序排序的主要内容,如果未能解决你的问题,请参考以下文章

dataframe 按照指定顺序排序

dataframe 按照指定顺序排序

pandas使用sort_values函数将dataframe按照指定数据列的内容对dataframe的数据行进行排序(sort dataframe rows by a specific column

PHP二维数组按照指定的顺序排序

oracle按照指定顺序进行排序

php按照指定顺序的排序