我需要做与我的函数相同的事情:df_g['Bidfloor'] = df_g[['Sitio', 'Country']].merge(df_seg, how='left').Precio
但是在Country
上,而不是完全相同的行上,只有前2个键,因为我不能更改数据的语言。所以我只想读取Country
列的前两个键,而不是Country
列的所有键
数据框g:
Sitio,Country
Los Andes Online,HN - Honduras
Guarda14,US - Estados Unidos
Guarda14,PE - Peru
数据框分段:
Sitio,Country,Precio
Los Andes Online,HN - Honduras,0.5
Guarda14,US - United States,2.1
我需要的是:
Sitio,Country,Bidfloor
Los Andes Online,HN - Honduras,0.5
Guarda14,US - United States,2.1
Guarda14,PE - Peru,NULL
您需要额外的键来帮助合并,我使用
cumcount
来区分重复值只需添加和删除合并列,即可完成:
然后做:
退货
相关问题 更多 >
编程相关推荐