I need to get the items available from the two lists and then check if they are available in a string.
list1 = ['Cat', 'Dog', 'Crow']
list2 = ['Wild', 'Pet']
Df
ind Camp
1 Ball_Dog_Wild_Ear
2 Dog_Ball_Pet_Dos
3 Wild_Dos_Cat_Pre
4 Pet_Cer_Crow_Tre
5 Dos_Cat_Wild_Tre
I need to split the "Camp" based on "_" and then check on position 0 and 2 if the item from list exact matches.
Desired output:
ind Camp
1 Ball_Dog_Wild_Ear False #False because 0 position has ball(not in list)
2 Dog_Ball_Pet_Dos True #True because 0 and 2 both available in the list
3 Wild_Dos_Cat_Pre True
4 Pet_Cer_Crow_Tre True
5 Dos_Cat_Wild_Tre False
I can do split via df['Camp'].str.rsplit("_", expand=True)
and check with .isin() but not sure how we can do for each rows to get the desired output.