I'm new with python and pandas so here's my question:
I have two dataframes, df1 has two columns one for labels and one for integers which correspond to the Toal of each label while df2 contains the quantity used by day. I would like to subtract each row of df2 until df1 is equal or closer to 0 and add a column to df1 the date of the last row subtracted (it could be in a new dataframe df3). The subtraction needs to have two conditions where:
df1 = DF with Totals
df2 = DF with quantities
I hope someone can help me.
I believe a .cumsum() and .idxmin() will help with this.
This should give you a three-column data frame with one row per label, the date when the running total was closest to but not lower than 0, and the amount (Total - Running Quantity at that date).