Assume this df
df = pd.DataFrame({'a':['texttext',[1,2,3,4,5],[2,3,4,5]],
'b':['texttext',[1,2,5,8,9,10],[2,3,5]]})
I would like to get three extra columns that get: a) the common values of the list intercetcion b) the values en list of column a not in column b c) the values in column c not in column a
Note that the df might contain (like in row 1) other NON LIST values. That makes things complicated
I now how to make the operations for the lists:
common = [x for x in lst1 if x in lst2]
minus = [x for x in lst1 if x not in lst2]
plus = [x for x in lst2 if x not in lst1]
But I am not able to figure out how to implement it in pandas. even for a method (for .apply) I have to sent two values In a one liner I have to check the type.
Some idea?
Thanks a lot
EDIT: Expected output:
expected = pd.DataFrame({'a':['texttext',[1,2,3,4,5],[2,3,4,5]],
'b':['texttext',[1,2,5,8,9,10],[2,3,5]],
'common':['',[2,5],[2,3,5]],
'minus':['',[3,4,5],[4]],
'plus':['',[ 8, 9, 10],[]]})