I have a dataframe with ip address in one of the column and I want to add a new column called "country" from another dataframe based on the location of ip address that lies between lower and upper ip address.
Two dataframes
import numpy as np
import pandas as pd
df1 = pd.DataFrame({'ip': [0.1,2.5,3.5]})
df2 = pd.DataFrame({'low_ip': [3,2,7,10],
'high_ip': [5,3,9,11],
'country': ['A','B','A','C']})
print(df1)
ip
0 0.1
1 2.5
2 3.5
print(df2)
low_ip high_ip country
0 3 5 A
1 2 3 B
2 7 9 A
3 10 11 C
Required
ip country
0.1 NA
2.5 B because: 2 <= 2.5 <= 3
3.5 A because: 3 <= 3.5 <= 5