Count of values grouped per month, year - Pandas
Use GroupBy.transform
for columns with same size like original DataFrame:
df['Date'] = pd.to_datetime(df['Date'], format= '%d/%m/%y')
y = df['Date'].dt.year
m = df['Date'].dt.month
df['Count_d'] = df.groupby('Date')['Date'].transform('size')
df['Count_m'] = df.groupby([y, m])['Date'].transform('size')
df['Count_y'] = df.groupby(y)['Date'].transform('size')
print(df)
Date Val Count_d Count_m Count_y
0 2018-01-01 A 2 4 6
1 2018-01-01 B 2 4 6
2 2018-01-02 C 1 4 6
3 2018-01-03 D 1 4 6
4 2018-02-01 A 1 1 6
5 2018-03-01 B 1 1 6
6 2019-01-02 C 1 2 2
7 2019-01-03 D 1 2 2