Reputation: 95
I am working with a Pandas df in Python. I have the following input df:
Color Shape Value
Blue Square 5
Red Square 2
Green Square 7
Blue Circle 9
Blue Square 2
Green Circle 6
Red Circle 2
Blue Square 5
Blue Circle 1
I would like the following output:
Color Shape Count Sum
Blue Square 3 12
Red Square 1 2
Green Square 1 7
Blue Circle 2 10
Green Circle 1 6
Red Circle 1 2
Looking for something like pivot_table() but do not want the hierarchical index.
Upvotes: 1
Views: 493
Reputation: 95
The problem I am having is associated with indexing more than pivot tables. To remove the multiple index a simple:
df.reset_index()
does the trick just fine.
Upvotes: 1