I have a dataframe which you can build with this:
dflist=[['123',['abc','qw3','123']],
['ab12',['3e4r5','12we3','asd23','q2w3']]]
df=pd.DataFrame(dflist,columns=['check','checklist'])
And looks like this:
check checklist
0 123 [abc, qw3, 123]
1 ab12 [3e4r5, 12we3, asd23, q2w3]
I want to check if the item in column "check" is in the list in column "checklist". So I want the resulting dataframe to look like:
check checklist checkisin
0 123 [abc, qw3, 123] True
1 ab12 [3e4r5, 12we3, asd23, q2w3] False
I have tried several things including using .isin in various forms including apply/lambda. and directly.
This:
df['checkisin']=df.check.isin(df.checklist)
produces:
check checklist checkisin
0 123 [abc, qw3, 123] False
1 ab12 [3e4r5, 12we3, asd23, q2w3] False
which has two Falses.
Trying this: df['checkisin']=df.apply(lambda x:x.check.isin(x.checklist)) gives this error:
AttributeError: ("'Series' object has no attribute 'check'", 'occurred at index check')
Trying this:
df['checkisin']=df.apply(lambda x:x['check'] in x.checklist)
gives this error:
KeyError: ('check', 'occurred at index check')
I'm sure I'm missing something simple here. I know I could loop this, but looking for a Pandas Dataframe column wise solution as the DF I have is very large and trying to "most" efficiently handle.
Thanks!