获取一个 pandas 时报的总小时数? [英] Get total number of hours from a Pandas Timedelta?

查看:42
本文介绍了获取一个 pandas 时报的总小时数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取熊猫timedelta中的总小时数?

How can I get the total number of hours in a Pandas timedelta?

例如:

>>> td = pd.Timedelta('1 days 2 hours')
>>> td.get_total_hours()
26

注意:根据文档,.hours属性将返回小时 component :

Note: as per the documentation, the .hours attribute will return the hours component:

>>> td.hours
2

推荐答案

只需找出1小时可容纳多少timedelta

Just find out how many timedeltas of 1 hour fit into it:

import numpy as np

>> td / np.timedelta64(1, 'h')
26.0

这篇关于获取一个 pandas 时报的总小时数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆