I have a dataframe grouped by like this;
price quantity vat
date brand
20-Jun-13 Reebok 7.0 8 2.2
Adidas 12.0 3 3.8
Campus 2.5 38 4.2
Woodlands 23.0 9 7.2
Boot 3.2 35 3.3
21-Jun-13 Reebok 7.0 6 2.2
Adidas 12.0 23 3.8
Campus 2.5 18 4.2
Woodlands 23.0 29 7.2
Boot 3.2 15 3.3
22-Jun-13 Reebok 5.0 2 3.5
Adidas 10.0 5 2.8
Campus 2.0 50 3.5
Woodlands 25.0 4 6.5
Boot 2.5 10 2.8
How do I groupby 'date'
and 'brand'
and multiply 'price'
and 'quantity'
to calculate sales?
I've tried;
print data2.groupby(['date','brand'])['price'] * ['quantity']
I would like to calculate the total sales by date.
Your data is already grouped by date and brand, so why not just create a new sales column:
df['sales'] = df['price'] * df['quantity']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With