Python, Pandas Pivot Table: How to get Sum of SubCount?

  pandas, python

i want the sum of all subcounts printed in a pivot table.

table = pd.pivot_table(df, index = ['value1', 'value2'], values = ['value3'], aggfunc = [np.count_nonzero])

Output of print(table.loc[value1example]):

                                 count_nonzero
                               value3
value2
 value2examplea                           766
 value2exampleb                           265
 value2examplec                           19

I want the following:

                                 count_nonzero
                               value3
value2                                   950
 value2examplea                           766
 value2exampleb                           265
 value2examplec                           19

Do you have an idea?

Source: Python Questions

LEAVE A COMMENT