How can I create a Pivot Table that show sum() of group values, using my Pandas Data Frame?
IIUC, you need a sum of each cnpj
values, so I would use groupby as:
g = df.groupby('cnpj')['bc_icms'].sum().reset_index(name='sum')
that returns:
cnpj sum0 2364118000124 93567.241 2817342000124 17827.072 7374346000107 1497.703 8953538000122 686.004 54921580000189 108000.00
Hope that helps.
EDIT:
you can also use:
g = df.groupby(['cnpj','num_doc'])['bc_icms'].sum()
that returns the complete dataframe out:
cnpj num_doc2364118000124 15263 37353.10 15264 56214.142817342000124 10154 17827.077374346000107 14224 320.12 14231 385.04 14263 401.28 14279 391.268953538000122 12865 686.0054921580000189 112428 108000.00