python - counting unique value pairs in pandas -


i have dataframe 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 count number of unique (date, user) combinations each place — or, put way, number of 'unique visits' each city. new york one, san francisco two, , houston one.

i've tried doing below follows:

df.groupby([df.index, user, place]).place.size() returns total count each place. feel i'm missing obvious here, can't see is. help?

here's 1 way it, assuming convert index column named date, can pass in show above.

input:

df.groupby(['place', 'user', 'date']).place.count().groupby(level='place').count() 

output:

place houston          1 new york         1 san francisco    2 dtype: int64 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -