Skip to content
Advertisement

Calculating the sum of the quantities of one dataframe based on dates in another dataframe (Python)

Suppose I have a first df like this:

df1:

JavaScript

I also have a second df (df2) with the items, a date and a quantity

df2:

JavaScript

Now I want to sum the quantities from df2 where the date is between the columns date1 and date2. So my result would look like:

df3:

JavaScript

I’ve been starring at it for a while now and I really want to avoid a loop.

Is there an efficient way of obtaining the desired result??

Advertisement

Answer

JavaScript

output:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement