I have a dataframe with a date column and I would like to create a new column that tells me how many identical dates the dataset contains. This is a min example of the original data set:
df1:
date
2017/01/03
2017/01/03
2017/01/04
2017/01/04
2017/01/04
2017/01/05
I would like to create this date_count, so the target data set is:
df1:
date date_count
2017/01/03 2
2017/01/03 2
2017/01/04 3
2017/01/04 3
2017/01/04 3
2017/01/05 1
The actual code to create df1:
dict1 = [{'date': '2017/01/03', 'date_count': 2},{'date': '2017/01/03', 'date_count': 2},
{'date': '2017/01/04', 'date_count': 3},{'date': '2017/01/04', 'date_count': 3},
{'date': '2017/01/04', 'date_count': 3},{'date': '2017/01/05', 'date_count': 1}]
df = pd.DataFrame(dict1, index=['s1', 's2','s3','s1','s2','s3'])