I have a shipping records table with approx. 100K rows and I want to calculate, for each row, for each material, how many qtys were shipped in last 30 days. As you can see in below example, calculated qty depends on "material, shipping date". I've tried to write very basic code and couldn't find a way to apply it to all rows.
df[(df['malzeme']==material) & (df['cikistarihi'] < shippingDate) & (df['cikistarihi'] >= (shippingDate-30))]['qty'].sum()
| material | shippingDate | qty | shipped qtys in last 30 days |
|---|---|---|---|
| A | 23.01.2019 | 8 | 0 |
| A | 28.01.2019 | 41 | 8 |
| A | 31.01.2019 | 66 | 49 (8+41) |
| A | 20.03.2019 | 67 | 0 |
| B | 17.02.2019 | 53 | 0 |
| B | 26.02.2019 | 35 | 53 |
| B | 11.03.2019 | 4 | 88 (53+35) |
| B | 20.03.2019 | 67 | 106 (35+4+67) |