python - 根据数据框中的 id 比较两个数据框列
问题描述
我对 python 完全陌生。我有两个数据框属于相同的数据集,但一个是输入,一个是输出。
所以,这是我的输入数据框
Document_ID OFFSET PredictedFeature
0 0 2000
0 8 2000
0 16 2200
0 23 2200
0 30 2200
1 0 2100
1 5 2100
1 7 2100
所以在这里,我将其作为我的ml-model
. 它只给我这种格式的输出。
现在我的输出看起来像,
Document_ID OFFSET PredictedFeature
0 0 2000
0 8 2000
0 16 2100
0 23 2100
0 30 2200
1 0 2000
1 5 2000
1 7 2100
现在,在这两个数据框中,我想做的是
对于该 ID,对于该偏移量,输入特征与输出特征相同。如果是,那么我想在新列中添加 true 作为值,如果不是,那么它将添加 false 值。
现在,如果我们在示例数据中看到
for ID 0 , for offset 16 the input feature is 2200 and output feature is 2100 so it is a false.
有人可以帮我吗?任何事情都会有所帮助。
解决方案
如果DataFrame
s 和前 2 列中的值相同,则使用相同的索引值:
inputdf['new'] = inputdf['PredictedFeature'] == outputdf['PredictedFeature']
推荐阅读
- angular - 用于 ASP.NET Core API 应用和 Angular6 应用的 DockerCompose
- debian-based - Debian 5 是否有 augeas 版本 1.0
- apache-spark - 撤消规模数据pyspark
- angular - 我的primeng时间表出现但没有事件
- swift - Swift 选项卡式栏 2 URL
- java - 表格视图单元格内的JavaFX形状
- mongodb - 更新服务 MongoDB 失败
- sql - 带条件的 T-SQL OVER/PARTITION BY 查询
- ios - 面容 ID 评估流程无法正常工作
- angularjs - 在控制器的 ng-if 中使用服务功能