So basically, I am looking at survey data, and one of the questions has an answer where people can select multiple options. All these options will now be under one column, but based on the order in which the respondent has selected the options. So basically, when I perform value_counts() on the column, it looks like this:
A 10
B 15
C 6
D 19
E 23
A,B 2
A,C 5
A,B,E 7
E,A,C 4
B,C 6
..
So now I want to select a combination where respondents have selected at least one of A,B,C or D to this question, but not just A, just B, just C or just D. So in essence, I want the combinations where the selected option is more than one, and the options have at least A/B/C/D. Ex: (A,D,E), (A,B,F), (B,F) and so on.
I have tried splitting this with a simple delimiter and making a column for each option, but the problem is: not all the rows are of same length and also, the order is not always the same and all the first elements go under the first column, which again makes it useless. I have tried manually selecting the options from value counts, like:
df = df[(df['variable'] == 'A,D,E') | (df['variable'] == 'B,F')]
But I want to be able to automate this, but just don't know how.
I have also tried looking for a sub-string, creating a column, and adding all the numbers - but the issue with this is, it also takes respondents who answered just A, just B, etc. into consideration, which is not something I want.
x ='A'
df["A_column"]= df["variable"].str.find(x)
Can someone please help me with the logic of this?