python-3.x - 元组列表中的Python时间戳差异
问题描述
我在元组列表中有 FROM Timestamp 和 TO Timestamp 。我想获得元组列表中存在的时间戳差异(以分钟为单位)。
例如:
Timestamp_list = [
(Timestamp("2021-09-13 07:00:00"), Timestamp("2021-09-13 10:00:00")),
(Timestamp("2021-09-13 11:00:00"), Timestamp("2021-09-13 12:00:00")),
]
在上面的列表中,和之间的区别Timestamp('2021-09-13 07:00:00')
是Timestamp('2021-09-13 10:00:00')
分钟,和180
之间的区别是分钟。我总共有几分钟。列表中可能有 N 个 FROM 和 TO 时间戳。Timestamp('2021-09-13 11:00:00')
Timestamp('2021-09-13 12:00:00')
60
240
预期的结果应该是240
分钟。您能帮我用 Python 完成这项工作吗?谢谢你。
解决方案
尝试:
out = sum((b - a).seconds for a, b in Timestamp_list) // 60
print(out)
印刷:
240
推荐阅读
- css - 在 Shadow DOM 中,覆盖 CSS body *
- node.js - redis 客户端可以在没有安装 redis 数据存储的情况下工作吗?
- haskell - 持久 - 如何过滤记录列的字段
- python - 如何检查它是 Python 还是终端中的 Retina 显示器?
- python - Selenium + chromedriver 无法仅在某些页面中加载 HTML,但不能在其他页面中加载
- android - Android Studio 显示此错误“ASCII 打开文件”
- numpy - 你能帮我纠正这个值错误:数学域错误吗?
- r - 将带有日期(作为字符串)的列转换为只有年份的日期类型
- python - 在输出之前打印 pexpect 是带有 \r\n 的单行,而不是实际的 CR/LF 输出
- html - 标题对齐到左侧居中对齐的段落