'Create column from another dataframe with condition
I want to assign the labels in the df1 to df2 depending of df1['MinNum'] and df1['MaxMum']
df1
Label MinNum MaxNum
0 Rivière 0 0
1 Sols minéraux bruts 1 2
2 Sols peu évolués lithiques 3 4
df2
SOIL_ID
0 0.0
1 1.0
2 2.0
4 4.0
The condition is:
if df1['MinNum'] <= df2['SOIL_ID'] <= df1['MaxNum'] assign df1['Label'] to new label column for df2
I want to have this
SOIL_ID label
0 0.0 Rivière
1 1.0 Sols minéraux bruts
2 2.0 Sols minéraux bruts
4 4.0 Sols peu évolués lithiques
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
