pandas将增量时间列转换为一个唯一的单位时间

问题描述 投票:0回答:1

我正在使用熊猫数据框,其中有一个deltatime列,其值类似于:

{'deltatime':0天09:06:30,0天00:30:34,2天23:07:14}

如何将这些时间转换为一个单位,例如分钟或小时,但转换为一个单位,以便更好地在图形中可视化这些时间。有想法吗?

这里:https://pandas.pydata.org/pandas-docs/stable/user_guide/timedeltas.html

未阐明如何简化更改单位

pandas time timedelta units-of-measurement
1个回答
1
投票

您可以使用total_seconds()timedelta方法以秒为单位获取持续时间:

seconds = [t.total_seconds() for t in df['deltatime']

然后根据需要转换单位:

#to hours, i.e. 3600 seconds
seconds = [t.total_seconds()/3600 for t in df['deltatime']
© www.soinside.com 2019 - 2024. All rights reserved.