It's hard to operate directly with list values. You can concatenate the strings into one, using some separator character, and then check the condition:
import pandas as pd
df = pd.DataFrame({'STATUS': [['REQUESTED', 'RECEIVED'], ['XYZ'], ['RECEIVED']]},
index=[1, 2, 3])
print(df['STATUS'].str.join('|').str.contains('RECEIVED'))
Output:
1 True
2 False
3 True
Name: STATUS, dtype: bool
A more efficient option would be to replace the strings with numerical flags. This can be done really nicely since Python 3.6 using enum.Flag
.
import enum
import pandas as pd
class Status(enum.Flag):
REQUESTED = enum.auto()
RECEIVED = enum.auto()
XYZ = enum.auto()
df = pd.DataFrame({'STATUS': [Status.REQUESTED | Status.RECEIVED, Status.XYZ, Status.RECEIVED]}, index=[1, 2, 3])
print(df['STATUS'] & Status.RECEIVED)
Or, if you already have a data frame with strings:
import enum
import pandas as pd
from functools import reduce
class Status(enum.Flag):
REQUESTED = enum.auto()
RECEIVED = enum.auto()
XYZ = enum.auto()
df = pd.DataFrame({'STATUS': [['REQUESTED', 'RECEIVED'], ['XYZ'], ['RECEIVED']]}, index=[1, 2, 3])
df['STATUS_ENUM'] = df['STATUS'].apply(lambda v: reduce(lambda a, b: a | Status[b], v, Status(0)))
print(df['STATUS_ENUM'] & Status.RECEIVED)