【发布时间】:2021-12-29 07:42:30
【问题描述】:
我正在尝试根据另一个数据框中的值在数据框中创建一个新列。
df1 是,
Name Depth
A 100
A 120
B 200
df2 是,
Name Start_Depth End_Depth Zone
A 50 150 Zone1
A 150 200 Zone2
B 50 120 Zone3
B 120 300 Zone4
我想在df1中添加Zone列,基于两个条件,
- “名称”应在两个数据框中匹配
- 对于相同的“名称”,df1.Depth 应介于 df2 中的 Start_Depth 和 End_Depth 之间
输出df1,
Name Depth Zone
A 100 Zone1
A 120 Zone1
B 200 Zone4
【问题讨论】:
标签: python python-3.x pandas