[英]Combining python pivot tables
I would like to have a dataframe, created by combine only the total row values on two pivot tables and keeping the same column names, including the All column.我想要一个数据框,它通过仅组合两个数据透视表上的总行值并保持相同的列名(包括所有列)来创建。
testA:
sum
ALL_APPS
MONTH 2012/08 2012/09 2012/10 All
DESCRIPTION
A1 111 112 113 336
A2 121 122 123 366
A3 131 132 133 396
All 363 366 369 1098
testA:
sum
ALL_APPS
MONTH 2012/08 2012/09 2012/10 All
DESCRIPTION
A1 211 212 213 636
A2 221 222 223 666
A3 231 232 233 696
All 663 666 669 1998
As I result I would like to have a data frame that would look like:结果我想要一个看起来像的数据框:
2019/08 2019/09 2019/10 All
363 366 369 1098
663 666 669 1998
I tried:我试过:
A=testA.iloc[3]
B=testB.iloc[3]
my_series = pd.concat([A,B],axis=1)
But it does not do what I expected :(但它并没有达到我的预期:(
All All
MONTH
sum ALL_APPS 2019/08 363.0 NaN
2019/09 366.0 NaN
2019/10 369.0 NaN
All 1098.0 NaN
CUR_VER 2019/08 NaN 663.0
2019/09 NaN 666.0
2019/10 NaN 669.0
All NaN 1998.0
Try:尝试:
my_series=pd.concat([testA.iloc[-1], testB.iloc[-1]], axis=1, ignore_index=True).T
my_series.columns=map(lambda x: x[3], testA.columns)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.