from pandas import Series, DataFrame import pandas as pd df = pd.read_csv('data.csv') # pandas equivalent of Excel's SUMIFS function df.groupby('PROJECT').sum().ix['A001']
One concern I have with this implementation is that I'm not explicitly specifying the column to be summed.
Here's an example CSV data file (
data.csv), although I'm displaying | instead of commas to improve the visual appearance.
DATE | EMPLOYEE | PROJECT | HOURS 02/01/14 | Smith, John | A001 | 4.0 02/01/14 | Smith, John | B002 | 4.0 02/01/14 | Doe, Jane | A001 | 3.0 02/01/14 | Doe, Jane | C003 | 5.0 02/02/14 | Smith, John | B002 | 2.0 02/02/14 | Smith, John | C003 | 6.0 02/02/14 | Doe, Jane | A001 | 8.0
Equivalent Excel SUMIFS Function
If I were to open
data.csv in Excel and wanted to determine how many hours were worked on project A001, I would use the SUMIFS formula as follows:
=SUMIFS($D2:$D8, $C2:$C8, "A001")
Where the SUMIFS function syntax is:
=SUMIFS(sum_range, criteria_range1, criteria1, [criteria_range2, criteria2], …)