I have a dataframe where one of the columns has values such as below :
colA colB LISTCOL
USA 100 ['ABCD (Actor)', 'XYZ (Actor, Director)', 'PQR (Producer, Writer)']
UK 1200 ['45q34y(Actor,Director, Producer)', '123 (Actor, Director)']
I want to fetch out the elements of the list on each row in the LISTCOL column such that only the element that has Actor in it gets filtered.
I tried
df['ACTOR'] = df.apply(
lambda elem: [elem for elem in df['LISTCOL'].str if "Actor" in elem],
axis=1)
However it is not working. Unfortunately, my pandas is 0.23.4 and hence the df.explode() is not applicable for me in this case. Can you please assist how I can get the output i desire:
OUTPUT:
colA colB ACTOR
USA 100 ['ABCD', 'XYZ']
UK 1200 ['45q34y', '123']