I have a function which removes a string from a df column, if the string is present in the column of another df:
df1['col'] = df1['col'][~df1['col'].isin(df2['col'])]
The problem is that I now have to use this function on a column of tuples, which the function does not work with. Is there a way to easily transform the above function to accommodate for tuples? Data:
df1: df2:
index col1 index col
0 ('carol.clair', 'mark.taylor') 0 ('james.ray', 'tom.kopeland')
1 ('james.ray', 'tom.kopeland') 1 ('john.grisham', 'huratio.kane')
2 ('andrew.french', 'jack.martin')
3 ('john.grisham', 'huratio.kane')
4 ('ellis.taylor', 'sam.johnson')
Desired output:
df1
index col1
0 ('carol.clair', 'mark.taylor')
1 ('andrew.french', 'jack.martin')
2 ('ellis.taylor', 'sam.johnson')
The function does work if the column is first converted to string, however this raises an error later on in my code (I've tried using the .astype(tuple) command to solve this after removing the tuples, however the same error arose):
ValueError: too many values to unpack (expected 2)