I have a pandas dataframe such as:
ids year month visit_counts
112 2012 1 5
112 2012 5 25
414 2012 2 10
112 2013 5 10
414 2012 4 35
112 2013 8 16
112 2013 12 23
112 2014 2 20
112 2014 4 28
414 2013 6 15
414 2013 11 30
414 2014 2 24
414 2014 7 17
Each row represent a record with a date of occurrence. lets say, the first date of occurrence associated with id 112 is (year 2012, and month january (1)), and this first date of occurrence for different ids are different. I need to create new dataframe where for every id I want to have all the records within two years starting since the first date of occurrence.
So, the output dataframe should look like this:
ids year month visit_counts
112 2012 1 5
112 2012 5 25
414 2012 2 10
112 2013 5 10
414 2012 4 35
112 2013 8 16
112 2013 12 23
414 2013 6 15
414 2013 11 30
414 2014 2 24
It would be helpful, if anyone can provide the codes. Thank you!