Quantcast
Channel: Pandas SUMIF equivalent for two dataframes - Stack Overflow
Browsing all 3 articles
Browse latest View live

Answer by kait for Pandas SUMIF equivalent for two dataframes

If you wanted to keep all of the rows in df1, you could use this:def get_total_sales(x): mask = df2.store == x.store mask &= df2.invoicedate > x.startdate mask &= df2.invoicedate <=...

View Article


Answer by Scott Boston for Pandas SUMIF equivalent for two dataframes

Update easy fix:df1.merge(df2, on='store').query('startdate <= invoicedate <= enddate')\ .groupby(['store', 'startdate', 'enddate'])[['sales']].sum()\ .reindex(pd.MultiIndex.from_frame(df1),...

View Article


Pandas SUMIF equivalent for two dataframes

I have a DataFrame(df1) that looks like this with a store and startdate/enddate for each one: df1 = pd.DataFrame(data={'store': ['X','Y','Z'], 'startdate': ['2020-02-03', '2020-03-05', '2020-04-01'],...

View Article
Browsing all 3 articles
Browse latest View live


Latest Images