Percentage calculation in pivot table pandas with columns

被刻印的时光 ゝ 提交于 2019-12-04 15:34:22

To take the percents:

df_percent = temp_df.iloc[:, [0,1]].apply(lambda x: round(x / x.sum() * 100, 2), axis = 1)

to take the the variation, use diff

df_diff_percent = df_percent.groupby(level=[0,1]).diff().fillna(0)

                    sum
                    vendas_kg
      fabricante    ASATP   TEPOS
local   tipo    ordem       
AREA I  CAPSULA 1   0.00    0.00
                2   0.00    0.00
DILUIDO         1   0.00    0.00
                2   6.67    -6.67
AREA II CAPSULA 1   0.00    0.00
                2   -41.67  41.67
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!