python - 在 pandas 中查找两个不匹配的数据帧的增量
问题描述
有 2 个数据帧,在 2 个不同时间有读数:
DF1
Sensor ID Reference Pressure Sensor Pressure
0 013677 100.15 93.18
1 013688 101.10 95.23
2 013699 100.87 93.77
... ... ... ...
和
DF2
Sensor ID Reference Pressure Sensor Pressure
0 013688 120.01 119.43
1 013677 118.93 118.88
2 013699 120.05 118.85
... ... ... ...
鉴于“传感器 ID”值顺序在两个数据帧之间不匹配,创建包含这些读数之间差异的第三个数据帧的最佳方法是什么?
解决方案
Pandas 有这个漂亮的功能,它可以自动对齐索引。所以我们可以用它来解决你的问题:
df1.set_index("Sensor ID").sub(df2.set_index("Sensor ID"))
Reference Pressure Sensor Pressure
Sensor ID
13677 -18.78 -25.70
13688 -18.91 -24.20
13699 -19.18 -25.08
推荐阅读
- playwright - playwright-python - `handleSIGTERM=False` 导致 UnhandledPromiseRejectionWarning 并关闭浏览器
- sql - 雪花有条件地从表中删除
- node.js - Ghostscript 识别和裁剪区域?可能的?
- python - python conda环境安装包顺序
- php - 如何为 php 7.2 设置 phpredis
- reactjs - 带有 React 钩子的简单表单
- python - 熊猫替换不产生所需的输出
- python-3.x - Pandas 按组垂直合并值
- android - Android布局:在ConstraintLayout中对齐CheckBox和TextView的文本
- docker - WSL2 下的 Docker 客户端在没有 sudo 的情况下无法工作