I am trying to filter the word "No" out of multiple columns in my dataframe.
I am getting error TypeError: only list-like objects are allowed to be passed to isin(), you passed a [str]
Code:
answerlist = ('No')
gcofilter = gcofile[~gcofile[column_a].isin(answerlist) & ~gcofile[column_b].isin(answerlist) & ~gcofile[column_c].isin(answerlist)]
Is there a way around this? I
CodePudding user response:
You just need to add a comma
answerlist = ('No',)
CodePudding user response:
Define answerlist
as a list instead:
answerlist = ['No']
gcofilter = gcofile[~gcofile[column_a].isin(answerlist) & ~gcofile[column_b].isin(answerlist) & ~gcofile[column_c].isin(answerlist)]
Additionally, if your column_a
, column_b
, column_c
are actually column names instead of variable names storing column names, you should also put them within quotes, as follows:
answerlist = ['No']
gcofilter = gcofile[~gcofile['column_a'].isin(answerlist) & ~gcofile['column_b'].isin(answerlist) & ~gcofile['column_c'].isin(answerlist)]
CodePudding user response:
Try using a python list instead of tuple and parentheses to separate your conditions.
answerlist = ['No']
gcofilter = gcofile[(~gcofile[column_a].isin(answerlist)) & (~gcofile[column_b].isin(answerlist)) & (~gcofile[column_c].isin(answerlist))]