Python 根据另一列中的值替换值

Python 根据另一列中的值替换值,python,pandas,Python,Pandas,我有两个数据框架(数据和价格映射) 数据: 价格映射: G.ID Price 0 AR.1852218.1 0,1 1 AR.1852254.1 0,25 2 AR.1852549.1 0,33 我想根据标准Global id=G.id填写priceMapping数据框中的价格 提前感谢你的帮助 劳伦特使用由priceMapping创建的按系列,然后将不匹配的值替换为原始的按,因为不匹配的值会创建缺少的值: s = priceMapp

我有两个数据框架(数据和价格映射)

数据:

价格映射:

        G.ID       Price
0   AR.1852218.1     0,1
1   AR.1852254.1    0,25
2   AR.1852549.1    0,33
我想根据标准Global id=G.id填写priceMapping数据框中的价格

提前感谢你的帮助

劳伦特

使用由
priceMapping
创建的按系列,然后将不匹配的值替换为原始的按,因为不匹配的值会创建缺少的值:

s = priceMapping.set_index('G.ID')['Price']
Data['Price'] = Data['Global id'].map(s).fillna(Data['Price'])
print (Data)
      Global id Price
0  AR.1852218.1   0,1
1  AR.1852223.1   0,6
2  AR.1852251.1  0,56
3  AR.1852254.1  0,25
4  AR.1852257.1  0,25
5  AR.1852386.1  0,33
6  AR.1852549.1  0,33
另一个想法是使用:

s = priceMapping.set_index('G.ID')['Price']
Data['Price'] = Data['Global id'].map(s).fillna(Data['Price'])
print (Data)
      Global id Price
0  AR.1852218.1   0,1
1  AR.1852223.1   0,6
2  AR.1852251.1  0,56
3  AR.1852254.1  0,25
4  AR.1852257.1  0,25
5  AR.1852386.1  0,33
6  AR.1852549.1  0,33
s = priceMapping.set_index('G.ID')['Price']
Data['Price'] = Data['Global id'].replace(s)