I have data like as below:
df = pd.DataFrame({'date':['2020.2.1','2020.2.1','2020.2.1','2020.2.2','2020.2.1'],
'fips':[4,5,4,5,5]})
and I want to get a result counting the frequency of fips each day like as below, but I don't want to ignore the overlapped index column (desired output):
pd.DataFrame({'date':['2020.2.1','2020.2.1','2020.2.2'],
'fips':[4,5,5], 'count':[2,2,1]})
I tried df.groupby(['date','fips']).size()
But it ignore the index value at second row and first column '2020.2.1'.
Thanks in advance for your help..
df.groupby(['date', 'fips']).fips.agg(fips='first', freq=len)