I have a conditional formatting equation in Excel that i need pulled into python. I have been able to adjust the equation so that it is now a conditional statement in Python. However, my end goal needs to show summation by group for each condition.
##Condition From Excel adjusted into Python
condition = np.sum((df['ZONE'] != 'A') &
(df['ZONE'] != 'B') &
(df['ZONE'] != 'C'))
I have taken the above condition only partial and used a lambda functions below to give me 1/3 of what i need as it shows me by group the rows that dont contain A, however i also need to to show ones that dont contain A, B or C.
### Lambda Function only one condition part matched
groups = df.groupby('group')
groups.apply(lambda x: x[x['ZONE'] != 'A']['ZONE'].count())
##Current Output
There are only A, B, and C in the dataframe so I should expect '0' in every condition row.
| Groups | Condition |
|---|---|
| 1 | 0 |
| 2 | 0 |
| 3 | 0 |
| 4 | 4 |
| 5 | 0 |
The conditional formatting does not nor should not be used in the end, it was just a frame of reference for myself to expect how many instances i should expect. The lambda functions will actually be used in production if/when i can figure it out.