Python Forum
"SUMIF" type query in Python (help required) - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: "SUMIF" type query in Python (help required) (/thread-38382.html)



"SUMIF" type query in Python (help required) - BlainEillimatta - Oct-06-2022

Hello!

Hello all, great to be here!

I'm new to Python and have hit a brick wall with the following problem.

I have two dataframes and I would like to do a "sumif" type calculation to produce a new dataframe. I cannot figure it out.

The two df's are as so:
df1: "Customer ID", "Contract Name", "Date", "Amount"
df2: "Customer ID", "Contract Name", "Date"

I need to create a dataframe (df3) with the "Customer ID" and "Contract Title" with a sum of the Amount based on the following criteria:

Cust. ID and Contract Name Match and Date in df1 is AFTER date in df2.

I have concatenated the dfs but I am stuck with where to go next and I am struggling with the syntax of the criteria I need.

I would greatly appreciate anyone's help on this. I have a feeling it'll be obvious when someone explains how to do it, but I am frustrated I can't crack it.