Idea: I want to replace parts of data1 with newer price data.
Q1: Why are 'laptop' and 'printer' updated, but not 'chair'?
Q2: 'bed' in data2 does not exist for data1. In that case, there can't be an update to data1. I'm just wondering why there is no error like "'bed' has no match in data1"?
import pandas as pd
data1 =pd.DataFrame({'product_name': ['laptop', 'printer', 'tablet', 'desk', 'chair'],
'price': [0, 4, 6, 7, 9]
})
data2 =pd.DataFrame({'product_name': ['laptop', 'printer','chair','bed'],
'price': [89,32,34,355]
})
indi = data2['product_name']
for i in indi:
temp = data2.loc[data2['product_name'] == '%s'%i,'price']
data1.loc[data1['product_name'] == '%s'%i,'price'] = temp