【发布时间】:2020-05-30 13:58:18
【问题描述】:
我的第一个数据帧
dataframe1=
id number count1 count2
1 5225 10 30
2 2222 3 40
3 7121 30 50
第二个数据帧
dataframe2=
id value1 value2
1 4000 6000
3 2500 3300
3 7000 8000
输出
id value1 value2 number count1 count2
1 4000 6000 5225 10 30
3 7000 8000 7121 30 50
我试过了
dataframe2['a']=(dataframe1['number']>= dataframe2['value1']) & (dataframe1['number'] <= dataframe2['value2'])
它在a列中给出了True False值,我想做的是:对于Dataframe1“数字”列中的每个值,搜索它是否等于或介于“value1”和“value2”对中的任何一个Dataframe2 的值。此外,对于这个“number1”和“number2”对值,其各自的“id”必须与 Dataframe 中的“id”匹配。如果这都是真的,那么我想在 dataframe2 中插入 number、count1 和 count2
【问题讨论】:
标签: python-3.x pandas