I'm just getting into Pandas and trying to generate a spreadsheet for a car lot. I'm loving Pandas but it's slow going and I'm trying to generate some new columns that sum ...
import pandas as pd
data = pd.DataFrame({"Car":["Hyundai","Hyundai","Honda", "Honda"], "Type":["Accent", "Accent", "Civic", "Civic"], "Trans":["Auto", "Manual", "Auto", "Manual"], "TOTAL":[2,4,5,3]})
print data
print data.groupby(['Car', 'Type', 'Trans'])['TOTAL'].sum()
I'm getting the totally predictable ....
Car TOTAL Trans Type
0 Hyundai 2 Auto Accent
1 Hyundai 4 Manual Accent
2 Honda 5 Auto Civic
3 Honda 3 Manual Civic
Car Type Trans
Honda Civic Auto 5
Manual 3
Hyundai Accent Auto 2
Manual 4
Ideally what I'd love to pull off is.....
Car Type Auto Manual Total
Honda Civic 5 3 8
Hyundai Accent 2 4 6
My knowledge isn't that great of Pandas (yet), but I'm guessing it's an "apply" or an agg() function but so far, syntactically, I'm banging my head from the syntax errors, but I appreciate any pointers in the right direction. .. JW