As input I have two dataframes:
data1 = [{'code':100}, {'code':120}, {'code':110}]
data1 = pd.DataFrame(data1)
code
0 100
1 120
2 110
data2 = [{'category':1, 'l_bound':99, 'r_bound':105},{'category':2, 'l_bound':107, 'r_bound':110},{'category':3, 'l_bound':117, 'r_bound':135}]
data2 = pd.DataFrame(data2)
category l_bound r_bound
0 1 99 105
1 2 107 110
2 3 117 135
I want to get in the end the following dataframe, with additional column in the first dataframe as a category number if the code lies in the corresponding interval:
code category
0 100 1
1 120 3
2 110 2
Intervals are random and the original dataframes are pretty big. Looping with itertuples is too slow. Any pythonic solutions?