Sumif function between 2 dataframes

Viewed 72

I have 2 dataframes like this:

Type Year Start Year end Total
A 2020 2020 4
A 2019 2020 5
B 2018 2019 3
C 2017 2019 9
Type Year Amount
A 2017 2
A 2018 3
A 2019 1
A 2020 4
B 2017 1
B 2018 1
B 2019 2
B 2020 3
C 2017 4
C 2018 2
C 2019 3
C 2020 1

So for the first table, the field total should be the sum of the second table meeting 2 conditions (same type year >= & <=). It would be like the sumif function of excel.

So far, I have achieved this functionality by defining a function with masks and using apply over the dataframe. This approach works fine, however is very slow. Is there a way to perform this faster?

0 Answers
Related