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