具有值的数据帧ABC
id | price | type
0 easdca | Rs.1,599.00 was trasn by you | unknown
1 vbbngy | txn of INR 191.00 using | unknown
2 awerfa | Rs.190.78 credits was used by you | unknown
3 zxcmo5 | DLR.2000 credits was used by you | unknown
以及其他XYZ值
price | type
0 190.78 | food
1 191.00 | movie
2 2,000 | football
3 1,599.00 | basketball
如何将XYZ与ABC映射,以便使用XYZ价格中的值(数值)将ABC中的type更新为XYZ中的type。你知道吗
我需要的输出
id | price | type
0 easdca | Rs.1,599.00 was trasn by you | basketball
1 vbbngy | txn of INR 191.00 using | movie
2 awerfa | Rs.190.78 credits was used by you | food
3 zxcmo5 | DLR.2,000 credits was used by you| football
用过这个吗
d = dict(zip(XYZ['PRICE'],XYZ['TYPE']))
pat = (r'({})'.format('|'.join(d.keys())))
ABC['TYPE']=ABC['PRICE'].str.extract(pat,expand=False).map(d)
但是像190.78和191.00这样的值越来越不匹配了。 例如,在处理大量数据时,190.78应该与食物值相匹配,比如190.77与食物值不匹配,而食物值被赋予了其他值。198.78也与其他一些应该与食物匹配的不匹配
测向
df2型
使用
re
将类型更改为浮动
使用
pd.merge
输出
您可以执行以下操作:
输出
我假设您在
xyz
表中输入了一个错误,第三个价格应该是2000.78
,而不是2000
。你知道吗相关问题 更多 >
编程相关推荐