I want to select the rows from dataframe that have "apple" in their column, but the "PHRASE" column should not be considered as string but as a list with "|" separator. Phrase column can have None/NaN values.
import pandas as pd
df = pd.DataFrame({"PHRASE": ["apple and bannaa|bannana", None, "apple", "orange|bannana", "orange|apple|bannana"]})
print(df)
0 apple and bannaa|bannana
1 apple
2 orange|bannana
3 orange|apple|bannana
I want to select rows that have apple in them, but the row should be considered as list with "|" as separator.
Desired output:
1 apple
3 orange|apple|bannana
I tried to do this
result = df[df.PHRASE.str.split("|").str.contains("apple")]
but it does not work.