python - 从日期时间差中提取小时与舍入 1 - Pandas DataFrame
问题描述
有没有一个选项可以用小数点(8.4,9.2)提取小时的时差。当我使用
(arm['EndTime']-arm['StartTime']).astype('timedelta64[h]')
结果是 8.0 而不是 8.4,和 9 而不是 9.2 结果自动四舍五入为 0...我尝试使用以下代码
(arm['EndTime']-arm['StartTime']).astype('timedelta64[h]').round(1)
但它产生了相同的结果。
解决方案
您可以使用withSeries.dt.total_seconds
除以with :3600
Series.div
Series.round
(arm['EndTime']-arm['StartTime']).dt.total_seconds().div(3600).round(1)
推荐阅读
- android - android:在google doc中打开pdf时,webview有时会显示空白屏幕
- python - 使用python的json模块解析json请求
- r - 如何在ggplot2中为同一变量添加具有不同单位的第二个图例?
- laravel - 带有 vue js 和 laravel 的数据表
- python - Python 不执行使用 pip 安装的脚本
- linux - 将命令的输出用于另一个
- three.js - 具有多种材质的 Threejs 对象不适用于 RayCasting
- python - 将 django 与 aiohttp/asyncio 集成
- php - 在 AJAX 成功时显示成功消息
- java - 为什么 type param 不支持下限有什么具体的理由不支持