Suppose that I have df1 and df2 that looks like this:
df1:
start end group
index
a 1 3 x
a 3 6 x
a 6 9 z
b 1 7 y
b 7 15 x
b 15 17 y
c 1 4 z
c 4 9 z
c 9 15 z
df2:
value
index
a 1.0
a 4.8
a 7.0
b 2.0
b 5.0
b 6.0
c 2.0
c 3.0
c 14.0
I want to make a new column in df2 called group and assign it by condition that refers df2.value to df1.start and df1.end such as:
if df2.value >= df1.start and df2.value < df1.end:
df2.group = df1.group
So in index 'a' for example, range 1-3=x; 3-6=x; 6-9=z, in index 'b', range 1-7=y; 7-15=x; 15-17=y, and in index 'c', range 1-4=z; 4-9=z; 9-15=z
so the results will be like this:
df2:
value group
index
a 1.0 x
a 4.8 x
a 7.0 z
b 2.0 y
b 5.0 y
b 6.0 y
c 2.0 z
c 3.0 z
c 14.0 z
How can I achieve this?