如何将 timedelta(带天数)转换为总秒数

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

我需要将已用时间转换为总秒数。我用了三个函数,但没有成功。

第一个功能:

ny["Time Elapsed"].time()

AttributeError:“系列”对象没有属性“时间”

第二个功能:

ny["Time Elapsed"].total_seconds()

AttributeError:“Series”对象没有属性“total_seconds”

第三个功能:

ny["Time Elapsed"](int)

类型错误:“系列”对象不可调用

附有数据框的图片。

我正在尝试将经过时间列中的持续时间转换为秒。数据框的名称是“ny”。

python python-datetime
1个回答
0
投票

出现您的问题是因为您没有使用 .dt 访问器。你应该使用:

ny['tot_s'] = ny["Time Elapsed"].dt.total_seconds()
© www.soinside.com 2019 - 2024. All rights reserved.