Fastest way to merge pandas dataframe on ranges

后端 未结 3 940
小蘑菇
小蘑菇 2020-12-09 12:25

I have a dataframe A

    ip_address
0   13
1   5
2   20
3   11
.. ........

and another dataframe B



        
3条回答
  •  余生分开走
    2020-12-09 12:48

    Try pd.merge_asof

    df['lowerbound_ip_address']=df['ip_address']
    pd.merge_asof(df1,df,on='lowerbound_ip_address',direction ='forward',allow_exact_matches =False)
    Out[811]: 
       lowerbound_ip_address  upperbound_ip_address    country  ip_address
    0                      0                     10  Australia           5
    1                     11                     20      China          13
    

提交回复
热议问题