0

df

Brand | SPID | Amount  
-------------------    
abc  |  1  |  100
-------------------
bcd  |  2  |  350
-------------------
abc  |  2  |  50
------------------   
bcd  |  1  |  70
------------------

expected output

Brand  |  1  |  2  |  Total
---------------------------
abc  |  100  |  50  |  150
---------------------------
bcd  |  70  |  350  |  420
---------------------------
total|  170  | 400  |  570
---------------------------

I want to use pandas for this kind of output from a big dataframe. it is my very first time to post a question and I don't even know how to create a table for it but hoping you will get it. Thank you

Chris Adams
  • 18,389
  • 4
  • 22
  • 39
  • hi and welcome to SO. kindly use this as a guide when posting questions : https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples. dont post pics, it is better to post data. you could do a df.head().to_dict() and paste your code here – sammywemmy Mar 23 '20 at 08:33
  • Use `df.pivot_table(index='Brand', columns='SPID', values='Amount', margins=True, margins_name='Total', aggfunc='sum')` – Chris Adams Mar 23 '20 at 08:42

0 Answers0