如何通过ParentAuction列透视表,以使我得到如图所示的输出 [英] How to pivot table by ParentAuction column in such a way that i get output shown in picture
本文介绍了如何通过ParentAuction列透视表,以使我得到如图所示的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何使用pandas数据透视表获取输出,使得所有Make均按其各自的ParentAuction值进行细分
how do i use pandas pivot table to get output in such a way that all the Make gets segmented by their respective ParentAuction values
像这样, 输出
当我运行它时,
pd.pivot_table(df,columns=['Make','Sales','AVG PMV','AVG GrossProfit','Loss%'],values=['ParentAuction'])
我收到此错误
pandas.core.base.DataError: No numeric types to aggregate
i get this error
pandas.core.base.DataError: No numeric types to aggregate
推荐答案
让我们尝试一下:
df.set_index(['Make','ParentAuction']).unstack().swaplevel(0,1,axis=1).sort_index(axis=1)
输出:
ParentAuction Copart IAA \
AVG GrossProfit AVG PMV Loss% Sales AVG GrossProfit AVG PMV
Make
Acura 112.99 -15.53 36.46 96.0 NaN NaN
Audi 150.85 -13.04 32.95 88.0 NaN NaN
BMW 134.39 -14.65 34.91 212.0 185.62 -11.92
Buick 6.35 -29.42 46.97 66.0 90.90 -26.47
Cadillac 91.71 -17.88 41.46 82.0 NaN NaN
Chevrolet 133.87 -14.06 35.82 776.0 150.29 -12.04
Chrysler 83.15 17.14 38.66 194.0 NaN NaN
Dodge 99.07 -18.68 37.60 383.0 154.23 -12.10
Ford 122.57 -15.88 37.79 979.0 169.51 -12.58
GMC 107.94 -16.63 41.45 152.0 113.92 -13.19
ParentAuction
Loss% Sales
Make
Acura NaN NaN
Audi NaN NaN
BMW 27.14 210.0
Buick 47.22 72.0
Cadillac NaN NaN
Chevrolet 29.82 912.0
Chrysler NaN NaN
Dodge 31.46 426.0
Ford 30.69 1284.0
GMC 33.08 133.0
这篇关于如何通过ParentAuction列透视表,以使我得到如图所示的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文