I tried the suggestion from here: Python Pandas Conditional Sum with Groupby
Not sure what/where I did wrong. Can someone point out and help? Please....
Tried this:
df.groupby('c').aggregate(lambda x: x['a'][(x['a'] > 1) & (x['b'] == 1)].mean())
Replacing with my column headers and conditions, and changing to sum:
df1.groupby('Store').aggregate(lambda x: x['Units'][(x['Units'] > 0) & (x['Status'] == 'ACKD')].sum())
Got a list of errors, too long to post here. Guess the main one is:
KeyError: 'Units'
df1:
Store Units Sent Recd Status SentMth RecdMth RptMth Days
201 2 2021-03-15 2021-03-15 INTR 3 3 3 0
201 1 2021-03-15 2021-03-15 INTR 3 3 3 0
this one is working fine:
df1.groupby('Store')['Units'].aggregate(lambda x: x[x > 0].sum())
Store
201 7
202 7
Name: Units, Length: 79, dtype: int64