Wednesday, 14 June 2023

Two conditional clause count in pandas

I have a df which looks like this:

api_spec_id  type_of_change   label
213              Breaking      NaN
213              Breaking      major
213              Non-Breaking  patch
345              Non-Breaking  NaN
345              Non-Breaking  patch
345              Non-Breaking  patch
678              Breaking      NaN
678              Breaking      minor
678              Breaking      major
123              Breaking      NaN
123              Breaking      NaN

I want to calculate the unique number of api_spec_id where:

all type_of_change are breaking, where expected output would be 2 (ids: 678,123)

all type_of_change are non-breaking, where expected output would be 1 (id:345)

at least one type_of_change is breaking, expected output: 3 (ids:213,678,123)

at least one type_of_change is non-breaking, expected output: 2 (ids:213,345)

I am not sure how I can achieve this, any suggestions or ideas would be greatly appreciated.



from Two conditional clause count in pandas

No comments:

Post a Comment