重新排序pandas数据透视表中的列

时间:2014-10-28 05:16:31

标签: python pandas

如何重新排序此数据框中的“土地使用”列:

Region                       North         South
LandUse          Year                           
Corn             2005  149102.3744  2078875.0976
                 2010  201977.2160  2303998.5024
Developed        2005    1248.4416    10225.5552
                 2010     707.4816     7619.8528
Forests/Wetlands 2005   26511.4304    69629.8624
                 2010   23433.7600    48124.4288
Open Lands       2005  232290.1056   271714.9568
                 2010   45845.8112   131696.3200
Other Ag         2005  125527.1808   638010.4192
                 2010  257439.8848   635332.9024
Soybeans         2005   50799.1232  1791342.1568
                 2010   66271.2064  1811186.4512

目前,n#39; LandUse'按字母顺序排列。我希望它遵循以下顺序:

lst = ['Open Lands','Forests/Wetlands','Developed','Corn','Soybeans','Other Ag']

1 个答案:

答案 0 :(得分:1)

您可以df = df.loc[lst]重新排序索引。