I have a DataFrame that looks like below
ID Date Amount
10001 2019-07-01 50
10001 2019-05-01 15
10001 2019-06-25 10
10001 2019-05-27 20
10002 2019-06-29 25
10002 2019-07-18 35
10002 2019-07-15 40
From the amount column, I'm trying to get a 4 week rolling sum based on the date column. What I mean by that is, basically I need one more column (say amount_4wk_rolling) that will have a sum of amount column for all the rows that go back 4 weeks. So if the date in the row is 2019-07-01, then the amount_4wk_rolling column value should be the sum of amount of all the rows whose date is between 2019-07-01 and 2019-06-04 (2019-07-01 minus 28 days). So the the new DataFrame would look something like this.
ID Date Amount amount_4wk_rolling
10001 2019-07-01 50 60
10001 2019-05-01 15 15
10001 2019-06-25 10 30
10001 2019-05-27 20 35
10002 2019-06-29 25 25
10002 2019-07-18 35 100
10002 2019-07-15 40 65
I have tried using window functions except it doesn't let me choose a window based on the value of a particular column
Edit:
My data is huge...about a TB in size. Ideally, I would like to do this in spark rather that in pandas