I'm trying to add the column "Customer Name" but when I run the code, that category doesn't show up in the column. I checked the excel spreadsheet I'm sourcing from and it definitely exists there so I'm unsure why it's not included in the output:
Help would be greatly appreciated!
Edit: Here is a link to the spreadsheet I'm working with: https://files.catbox.moe/m6x7w0.xlsx
CodePudding user response:
If you want to know the sum of the sales and profit of the customers in every region, you can groupby both region
and customer name
.
df[['Region','Customer Name','Sales','Profit']].groupby(['Region','Customer Name']).sum().sort_values(['Region','Sales'])
Sales Profit
Region Customer Name
Central Roland Schwarz 0.556 -0.9452
Toby Swindell 1.112 -1.8904
Christopher Conant 1.248 -1.9344
Dorris liebe 1.624 -4.4660
Cari Schnelling 1.720 -2.8380
... ...
West Karen Ferguson 7182.766 878.4390
Jane Waco 7391.530 2073.2828
Edward Hooks 7447.770 589.7548
Ken Lonsdale 8472.394 426.6132
Raymond Buch 14345.276 6807.0879
[2501 rows x 2 columns]