Say I have two DataFrames, an "original" and "correction" dataframe such that
orig = pd.DataFrame({'Name':['A','B'],'Code':['9q8','7k2']})
Name Code
A 9q8
B 7k2
corr = pd.DataFrame({'Name':['A',],'Code':['9R8',]})
Name Code
A 9R8
How can I assign orig['Code']=corr['Code']
wherever orig['Name']==corr['Name]
without merging or iterating through each correction in corr and then each original in orig? The final result should look like this:
Name Code
A 9R8
B 7k2
I did see another stack overflow post similar to my current question, but in that example the answer used a merge and then a selection mechanism to get rid of the old rows that are no longer desired. However, I have no such selection mechanism.
For example, if I merge orig and corr, I get:
out = pd.merge(orig,corr,on='Name',how='outer')
Name Code
A 9q8
A 9R8
B 7k2
Which, If I'm looking at thousands of rows, leaves me no way to know which of A 9q8
and A 9R8
was the substitution and which wasn't. I can't use an indicator column to tell substitutions from non-substitutions, because deleting all entries that are "left-only" would also remove the entry B 7k2
.