这可能已经被问到了,但我一直没有找到答案。
我有两个数据帧:df1和GPS。我想合并(provider-col和Restaurant col),以在df1数据框中找到所述餐馆的位置。
df1 :
_________________________________________________
| Date | Courier | Provider | Price |
|-------------------------------------------------|
| 19 july | bicycle | Rest A | 50 |
| 19 july | bicycle | Rest B | 100 |
| 18 july | motorbike | Rest C | 125 |
| 18 july | motorbike | Rest X | 127 |
|_________________________________________________|
gps :
_________________________________________________
| Restaurant | Coordinates (LNG,LAT) |
|-------------------------------------------------|
| Rest Q | (50, 30) |
| Rest Z | (56, 33) |
| Rest A | (22, 31) |
| Rest B | (14, 34) |
| Rest E | (27, 30) |
| Rest X | (50, 30) |
| Rest C | (55, 36) |
|_________________________________________________|
期望的结果将是(如果可能的话):
_________________________________________________________________________
| Date | Courier | Restaurant | Price | Coordinates (LNG,LAT) |
|-------------------------------------------------------------------------|
| 19 july | bicycle | Rest A | 50 | (22, 31) |
| 19 july | bicycle | Rest B | 100 | (14, 34) |
| 18 july | motorbike | Rest C | 125 | (55, 36) |
| 18 july | motorbike | Rest X | 127 | (50, 30) |
|_________________________________________________________________________|
所需的DF还可以具有一个提供者列,其行与as餐厅列中的行相同。
GPS df包含我没有数据的餐厅,因此需要以某种方式跳过这些餐厅。
我尝试了内部合并:
merged_df = df1.merge(gps, left_on='Provider', right_on='Restaurant')
但这会返回一个空的df,其中所有正确的列但缺少行(我使用python BTW)。
请指教,谢谢! :)