Johan Nilssons Lifestream

Python Pandas groupby multiple columns

thank you for your help.

I have data that looks like this:

city,  room_type
A, X
A, Y
A, Z
B, X
B, Y
B, Y

I want my end result to look like this:

city, count(X), count(Y), count(z) 
A,  1, 1, 1
B,  1, 2, 0

I am grouping by city and I want to show the count of each room_type in each city.

Any way to do this with python pandas? Thank you.

I learned SQL years ago and think that it may have been possible. I'm sure python can do the same. Thanks!

via Stack Overflow

blog comments powered by Disqus
Get the source for phplifestream at Github