Audience Ad
Audience1 Audience4.Ad1.image
Audience2 Audience1.Ad4.image
Audience3 Audience7.Ad1.image
Audience4 Audience2.Ad3.image
Audience5 Audience9.Ad1.image
Audience6 Audience4.Ad2.image
Audience7 Audience5.Ad1.image
Audience8 Audience7.Ad3.image
Audience9 Audience8.Ad1.image
Audience10 Audience9.Ad1.image
This is some sample data. What I am trying to do is to look in the Ad column and if it contains anything from the Audience column replace it with nothing. The most difficult part for me here is that on the left might say Audience1 and on the right Audience2 so that they are not the same. If they were I know how to implement this but unfortunately, they are not!
So the expected result will look like this
Audience Ad
Audience1 Ad1.image
Audience2 Ad4.image
Audience3 Ad1.image
Audience4 Ad3.image
Audience5 Ad1.image
Audience6 Ad2.image
Audience7 Ad1.image
Audience8 Ad3.image
Audience9 Ad1.image
Audience10 Ad1.image
The way I thought of doing this is by going through the Audience column with a for loop and then if I find that any of the elements of the Audience column is contained in the Ad column delete it.
This is how I tried to solve it but I am stuck on what to put in the return statement (if the rest of the logic of course is correct):
def replace(text):
for i in df['Audience']:
if i in text:
return ???
df['Ad'] = df['Ad'].apply(replace)
Any help would be appreciated!