Python Pandas VLookup具有多个等效的列

时间:2016-04-11 13:32:35

标签: python pandas vlookup

我有一些模拟结果,我希望与我为其特定坐标保持的一些静态信息配对。

我正在使用pandas,key数据框如下所示:

Orig_lat    Orig_lng    Dest_lat    Dest_lng    Site    Lane_1
51.4410925  -0.0913334  51.4431736  -0.0681643  6   E
51.4431736  -0.0681643  51.4410925  -0.0913334  6   W
51.6300955  -0.0781079  51.6489284  -0.0602954  7   N
51.648917   -0.0600521  51.6299841  -0.0779832  7   S
51.4648078  -0.301316   51.4573656  -0.3219232  9   S
51.4573656  -0.3219232  51.4649063  -0.3013827  9   N
51.412392   0.0743042   51.4088694  0.0800096   11  S
51.4088694  0.0800096   51.412392   0.0743042   11  N
51.4728599  -0.0235216  51.4804927  -0.0231821  14  N

结果dataframe如下所示:

distance    duration    duration_in_traffic Orig_lat    Orig_lng    Dest_lat    Dest_lng    
1456736402  1670    186 337 51.4431736  -0.0681643  51.4410925  -0.0913334
1456736416  508 73  73  51.4380877  -0.2131928  51.4417083  -0.2168077
1456736416  508 71  71  51.4417083  -0.2168077  51.4380877  -0.2131928
1456736417  578 83  82  51.5229177  -0.4402988  51.5180086  -0.4391647
1456736417  578 79  79  51.5180086  -0.4391647  51.5229177  -0.4402988
1456736417  894 148 155 51.489123   -0.3015009  51.4886771  -0.2894982
1456736418  894 170 163 51.4886771  -0.2894982  51.489123   -0.3015009
1456736418  410 88  88  51.5294107  0.107865    51.5296292  0.1019929
1456736418  410 91  90  51.5296292  0.1019929   51.5294107  0.107865
1456736419  821 90  102 51.6043935  -0.340337   51.6038698  -0.3521945
1456736419  821 96  121 51.6038698  -0.3521945  51.6043935  -0.340337
1456736419  263 48  47  51.3718957  -0.0471616  51.3741868  -0.0480754
1456736420  263 48  48  51.3741868  -0.0480754  51.3718957  -0.0471616
1456736421  426 59  58  51.5122705  -0.2177689  51.5086821  -0.2156843
1456736421  426 55  70  51.5086821  -0.2156843  51.5122705  -0.2177689
1456736421  471 57  57  51.3782746  -0.1864154  51.3800551  -0.1916053

我希望从密钥中收集SiteLane_1列,并使用resultsOrig_lat,{{1}将这些列加入Orig_lng数据框},Dest_lat,给予:

Dest_lng

我如何使用merge实现此目的?

1 个答案:

答案 0 :(得分:2)

IIUC在列Orig_latOrig_lngDest_latDest_lng上使用merge

print pd.merge(dataframe, key, on=['Orig_lat','Orig_lng','Dest_lat','Dest_lng'])
   distance  duration  duration_in_traffic   Orig_lat  Orig_lng   Dest_lat  \
0      1670       186                  337  51.443174 -0.068164  51.441092   

   Dest_lng  Site Lane_1  
0 -0.091333     6      W