我使用以下代码制作了一个大型数据透视表:
sector_pivot = pd.pivot_table(df_final,index=["sector"],values=["os_total_pnl_pos_sum"],
columns=["roll"],aggfunc=[np.sum])
部分输出如下(为格式道歉):
sum sum sum sum sum sum sum sum sum sum sum sum sum sum
os_total_pnl_pos_sum os_total_pnl_pos_sum os_total_pnl_pos_sum os_total_pnl_pos_sum os_total_pnl_pos_sum os_total_pnl_pos_sum os_total_pnl_pos_sum os_total_pnl_pos_sum os_total_pnl_pos_sum os_total_pnl_pos_sum os_total_pnl_pos_sum os_total_pnl_pos_sum os_total_pnl_pos_sum os_total_pnl_pos_sum
roll 10 100 101 102 103 104 105 11 12 13 14 15 16 17
sector
Advertising -2768.93274462 0 0
Airlines 0 -448.557534604 797.947770979 -3.10303164709 -2107.36065042 2174.67385899 695.182923208 1172.2239131
Apparel 0 -351.990936703 -2161.52276072 -644.508592818 -44.7798946194 0
Auto Manufacturers -186.228471603 1299.31914156 392.870813868 -2243.32482513 -295.450523892 134.410760607 -929.822089284 431.591057538 0 65.8123435544 -1421.32300134 559.447051101
Auto Parts&Equipment 592.371021691 1797.97308108 -606.285971327 1065.24853376 -185.311144228 201.355320854 -1457.18258363 -542.117148995 -7208.42760875 1541.68966742 -745.85858174 4152.24644225 -10269.0697919 1513.97875905
Banks 4361.73793108 -789.273834214 1566.3554511 -1964.65020745 1226.86345927 4602.16672398 2767.93707955 87.251053072 1104.41805991 -3668.99517044 -2352.0099824 901.340280997 4616.76040397 -4616.13513286
输出正确,除了卷的顺序外,最小卷为4,最大卷为105,因此::p
10,100,101,102,103,104,105,11,12,13,14,15,16,17.....
它应该像这样:
4,5,6,7,8,9,10,11,12,13,14,....99,100,101,102,103,104,105
有人可以让我知道如何将列重新排序为顺序吗?我看过其他类似的问题,但看不到如何解决此问题。
谢谢