AnsweredAssumed Answered

Pandas Pivot Table with rounding

Question asked by LANDVEST on Nov 9, 2018
Latest reply on Nov 13, 2018 by LANDVEST

I'm attempting to add in subtotals to a pivot table from a very basic array. The first example I provide I derived on my own, but this has no subtotals for each group.

The second example I borrowed and honestly I don't really get how it works just yet, and I cannot get a round to work.

pd.pivot_table(df.round({'ACRES':1}),values = 'ACRES', index = ['SUPER_TYPE','STRATA', 'OS_TYPE'], aggfunc=np.sum, margins = True)


2nd example:

df.groupby(['SUPER_TYPE']).apply(lambda sub_df: sub_df.pivot_table(index=['STRATA', 'OS_TYPE'], values=['ACRES'], margins=True) )


I'm guessing there are a number of ways to go about this. Thanks in advance!