1
整理整顿我有熊猫的follwing透视表:透视表
Division BU/CF Allocation Key CurrentHC
0 Central Functions A NEF 3
1 B NEF 2
2 C EXP 1
3 NEF 4
4 D NEF 3
5 Xerxes E NLE 4
6 F NLE 1
7 G NLE 1
8 H NLE 5
Python的排序明显的划分和BU/CF字母。我如何将自己的订单应用到数据透视表。
所需的输出:
Division BU/CF Allocation Key CurrentHC
0 Central Functions D NEF 3
1 B NEF 2
2 C EXP 1
3 NEF 4
4 A NEF 3
5 Xerxes E NLE 4
6 H NLE 5
7 G NLE 1
8 F NLE 1
代码我用来创建数据透视表:
#Create full report pivot
report_pivot = pd.pivot_table(full_report, index=["Division","BU/CF", "Allocation Key"],
values=["Previous HC", "New Hire", "Resigned", "In", "Out", "Current HC", "Delta"],
fill_value=0)
我设法这样做是为了重新排列列:
# Reorderr columns
cols = [ "Previous HC", "New Hire", "Resigned", "In", "Out","Delta", "Current HC"]
report_pivot = report_pivot[cols]
是否有索引类似的方式。特别是 “BU/CF”
*我排除在外,除了当前HC到表中简化上述
也许thatone帮助:http://stackoverflow.com/questions/10595327/pandas-sort-pivot-table请给出一个完整的代码和数据,以便我们可以轻松地适应一个解决方案。 – tfv
我添加了我用来制作数据透视表 – alpenmilch411
看看你想要的DF的代码,它绝对不清楚“我自己的订单”是什么意思。你能定义排序标准吗? – MaxU