I have a column in a dataframe which contains lists. I want to be able to remove elements from these lists based on elements that I have in another list (as shown below).
I tried to use list comprehension but it seems to give no result.
import pandas as pd
sys_list = ['sys1', 'sys2', 'sys3']
df = pd.DataFrame({'A':[['sys1', 'sys2', 'user1'],
['user3', 'user6', 'user1'],
['sys1', 'sys2', 'sys3']]})
df['A'] = [item for item in df['A'] if item not in sys_list]
print(df)
A
0 [sys1, sys2, user1]
1 [user3, user6, user1]
2 [sys1, sys2, sys3]
I need to achieve this:
A
0 [user1]
1 [user3, user6, user1]
2 []
Any thoughts?