Friday, 9 August 2013

counting unique values in pandas

counting unique values in pandas

I have a dataframe like the below:
place user count item
2013-06-01 New York john 2 book
2013-06-01 New York john 1 potato
2013-06-04 San Francisco john 5 laptop
2013-06-04 San Francisco jane 6 tape player
2013-05-02 Houston michael 2 computer
I'm trying to count the number of unique (date, user) combinations for
each place. So for New York it would be one, for San Francisco it would be
two, and for Houston it would be one.
I've tried doing the below follows:
df.groupby([df.index, user, place]).place.size() but that just returns the
total count for each place. I feel like I'm missing something really
obvious here, but I can't see what it is. Any help?

No comments:

Post a Comment