My dataframe looks like this:
ID Date
1001 2020-01-01
1001 2020-02-01
1002 2020-01-01
1002 2020-02-01
1002 2020-03-01
I wanted to create a df with unique ID values and how many times that ID was repeated along with the date. I tried the following code:
df.groupby(['ID','Date'])['ID'].count()
The output I got was:
ID Date
1001 2020-01-01 1
2020-02-01 1
1002 2020-01-01 1
2020-02-01 1
2020-03-01 1
But what I want to create is this, i.e. column name 'Count' and should be in df format:
ID Date Count
1001 2020-01-01 1
2020-02-01 2
1002 2020-01-01 1
2020-02-01 2
2020-03-01 3
The output is very close and only a slight tweaking is required. Can someone help me with this?