I have a data set that looks like this-
ID Search Provider
1 Yes A
1 Yes B
1 No B
1 No C
2 Yes D
2 Yes A
2 Yes B
2 No B
2 No C
What I want to find out is if the Providers for Search==Yes
is different from Search==No
for a given ID. E.g.- 'ID 1', 'Search=No' goes to Providers B,C whereas 'Search=Yes' goes to Providers A,B. So the provider A is new for ID 1.
I know I can use the isin
function to identify the unique values between two lists. However, how do I do it across multiple rows of ID and Search? And how do I compile the Provider values into lists for each subgroup defined by ID and Search? I guess I will need to use nested loops but not being able to write the code. Would really appreciate if someone can help me on this.