I'm trying to replace string in one the columns inside my dataframe(df). Here's what df looks like:
0 1
0 2012 Black Toyota Corolla White/Black/Red
1 2013 Red Toyota Camry Red
2 2015 Blue Honda Civic Blue
3 2012 Black Mazda 6 Black/Red/White
4 2011 White Nissan Maxima White/Red/Black
Sometimes, column 1 has multiple color values, sometimes only a single value. I would like to take however many values there are in column 1, check if any of those exist in column 0 and remove that value from column 0.
I've tried approaching it this way.
def removeColor(main,sub):
for i in sub.split('/'):
main = main.str.replace(i, '')
return(main)
>>> df['0'] = df['0'].map(lambda x: removeColor(x['0'],x['2']))
This results in a TypeError.
TypeError: string indices must be integers
My expected output looks like below:
0 1
0 2012 Toyota Corolla White/Black/Red
1 2013 Toyota Camry Red
2 2015 Honda Civic Blue
3 2012 Mazda 6 Black/Red/White
4 2011 Nissan Maxima White/Red/Black
df['0'].str.replace('|'.join(df.iloc[:,1].str.replace('/','|')),'')?