I have two columns within a data frame containing strings. For example,
import pandas as pd
import numpy as np
data = [['Oct-2019', 'Oranges + Grapes + Pears', 'Grapes + Pears'],
['Nov-2019', 'Oranges + Grapes + Pears', 'Oranges + Grapes + Pears']]
df = pd.DataFrame(data, columns =['Date', 'Previous shopping list', 'Recent shopping list'])
print(df)
Fish = ['Salmon', 'Trout']
Fruit = ['Oranges', 'Grapes', 'Pears']
Date PSL RSL
0 Oct-2019 Oranges + Grapes Grapes + Pears
+ Pears + Salmon
1 Nov-2019 Oranges + Grapes Oranges + Grapes
+ Pears + Trout + Pears
I want to compare the strings in both columns and have a text output to a new column that says what has changed between the two lists. Such as, creating a column that will check for the strings related to "Fruit" and output what fruit has been dropped from the recent shopping when compared to the previous list previous shopping list. See Desired output below:
Date PSL RSL Fruit lost Fish Lost
0 Oct-2019 Oranges + Grapes Grapes + Pears Oranges Salmon
+ Pears + Salmon
1 Nov-2019 Oranges + Grapes Oranges + Grapes Trout
+ Pears + Trout + Pears
How would I be able to achieve this in using pandas! Apologies if this was not clear the first time!
Thank you for any suggestion/help!