I have a data frame and an updated version of the same data frame with the colour in row 1 changed, row 2 deleted and one row appended.
I would like to append rows with a new ID to the old data frame , then compare both data frames and write the comparison result (e. g. "New entry", "Updated colour", "Entry deleted" or "No changes") into a "Compare" column.
Name Colour ID Compare
0 Lisa Red Apple
1 Anna Blue Banana
2 Anna Yellow Orange
3 Max Green Pear
Name Colour ID
0 Lisa Purple Apple
1 Anna Yellow Orange
2 Peter Pink Grape
I have tried several approaches with .iloc and .where, however I am too unexperienced with selection/manipulation, so it didn't work out. Here is what I am trying to achieve:
Name Colour ID Compare
0 Lisa Red Apple Colour changed
1 Anna Blue Banana Entry deleted
2 Anna Yellow Orange No changes
3 Max Green Pear New entry
I'm thankful for any help.
This is to create the data frames:
import pandas as pd
data = {'Name': ['Lisa', 'Anna', 'Anna', 'Max'],
'Colour': ['Red', 'Blue', 'Yellow', 'Green'],
'ID': ['Apple', 'Banana', 'Orange', 'Pear'],
'Compare': ['','','','']}
df = pd.DataFrame(data, columns = ['Name', 'Colour', 'ID', 'Compare'])
updatedDf = df.copy()
updatedDf = updatedDf.iloc[:, :-1]
updatedDf.set_value(0, 'Colour', 'Purple')
updatedDf = updatedDf.drop(1)
newrow = ['Peter', 'Pink', 'Grape']
updatedDf.loc[len(updatedDf)] = newrow
updatedDf = updatedDf.reset_index(drop=True)