0

I have two data frames that look like this:

Table A

min     max     quantity
--------------------------
0       2.0        1
3.0     5.5        2
...     ...      ...

Table B

price     ...      ...
--------------------------
2.3
3.5
4.9

the outcome I want is to assign the quantity to table B based on table A range:

price     ...    ...   quantity
-------------------------------
2.3                       1
3.5                       2
4.9                       2

The other solutions I have seen use int and it doesn't work with float data

I tried using this method:

B['quantity'] = A.loc[(B['price'] >= A['min']) & (B['price'] <= A('max'))] = A['quantity']

don't know how to end it, how to specify to look at quantity for that range.

Sugestions for different ways to answer this also welcomed.

Daniel
  • 353
  • 1
  • 8
  • `pd.merge_asof(df2, df1, left_on='price', right_on='min')` + eventually filtering/masking if you have overlapping intervals – mozway Apr 07 '22 at 11:12

0 Answers0