I have a set of data and I would like to count the occurrence of 'Bad' for a same number, and the result should show the count of 'Bad' in a new column, which is same function the COUNTIFS excel formula =COUNTIFS(N:N,N2,O:O,"Bad")
I have try to use the code below:
countbad = df.groupby('No')['Status'].value_counts().reset_index(name='count')
df['CountBad'] = countbad('count')
but the result I get is include counting based on Good/Moderate as well.
Is there any way to made the 'Bad' as the condition to count the number of occurrence and get exactly what I needed without changing the dataframe structure?
Thanks