I would like to join two tables in Pandas.
df_types Contains range size of type product (5000 rows)
| Table: TYPES | | |
|--------------|----------|------|
| size_max | size_min | type |
| 1 | 5 | S |
| 6 | 16 | M |
| 16 | 24 | L |
| 25 | 50 | XL |
Dataframe code in Pandas:
df_types = pd.DataFrame([[1,5,'S'],
[6,16,'M'],
[16,24,'L'],
[25,50,'XL']],
columns = ['size_min','size_max','type'])
df_products Contains products id and size (12000 rows)
| Table: Products | |
|-----------------|------|
| id_product | size |
| A | 6 |
| B | 25 |
| C | 7 |
| D | 2 |
| F | 45 |
| E | 10 |
| G | 16 |
Dataframe code in Pandas:
df_products = pd.DataFrame([['A',6,],
['B',25],
['C',7],
['D',2],
['F',45],
['E',10],
['G',16]],columns = ['id_product','size'])
I´d like to make this SQL join in Pandas:
SELECT *.df_products
type.df_types
FROM df_products LEFT JOIN df_types
ON df_products.size >= df_types.size_min
AND df_products.size <= df_types.size_max
RESULT:
| id_product | size | type |
|------------|------|------|
| A | 6 | M |
| B | 25 | XL |
| C | 7 | M |
| D | 2 | S |
| F | 45 | XL |
| E | 10 | M |
| G | 16 | M |
thank you! ;-)