I am trying to work out the rolling difference between 2 timeseries DataFrames.
I have 2 data sets, df1 has an inbound timeseries and df2 an outbound series.
        Date    Code    Quantity
0   10/01/2019  A   20
1   10/01/2019  B   12
2   10/01/2019  C   10
3   11/01/2019  A   2
4   11/01/2019  B   30
5   11/01/2019  C   2
6   11/01/2019  D   1
7   12/01/2019  A   4
8   12/01/2019  B   6
9   12/01/2019  D   3
10  12/01/2019  E   2
11  13/01/2019  A   10
12  13/01/2019  B   12
13  13/01/2019  C   1
df2 - Out
    Date     Code   Quantity
0   11/01/2019  A   5
1   11/01/2019  B   1
2   11/01/2019  C   3
3   12/01/2019  A   100
4   12/01/2019  D   2
5   12/01/2019  E   1
6   13/01/2019  B   1
7   13/01/2019  C   1
I am trying to calculate the quantity at the end of each date (df1[quantity] - df2[quantity]), then add this to the quantity from the end of the previous day, with the stipulation that the quantity can not be <0 at any point.
Desired Output
     Date      Code Quantity
0   10/01/2019  A   20
1   10/01/2019  B   12
2   10/01/2019  C   10
3   11/01/2019  A   17
4   11/01/2019  B   41
5   11/01/2019  C   9
6   11/01/2019  D   1
7   12/01/2019  A   0
8   12/01/2019  B   47
9   12/01/2019  D   2
10  12/01/2019  E   1
11  13/01/2019  A   10
12  13/01/2019  B   58
13  13/01/2019  C   9
I think that a function will be the best way to achieve the desired output, but haven't been able to find anything to do this.
 
    