My dataframe looks like this
Year X
2000 a
2000 b
2004 c
2004 d
2004 e
2001 f
I would like to add a new column that contains the sum of all rows associated with a specific year. The output would look like this:
Year X Total
2000 a 2
2000 b 2
2004 c 3
2004 d 3
2004 e 3
2001 f 1
For example, the total number of rows with the year '2004' is three, so the number three is in the total column for every row associated with the value '2004'
How would I go about adding this column?