![](/img/trans.png)
[英]Insert with Python into InfluxDb error: 'datetime.timedelta' object has no attribute 'total_seconds'
[英]AttributeError: 'numpy.timedelta64' object has no attribute 'total_seconds' with Pandas
我正在尝试将 sniffTime 转换为秒数。 我已经在 Python Pandas DataFrame中查看了将 timedelta64[ns] 列转换为秒,但是该解决方案不起作用。 我认为熊猫线可能有问题。
print(sniffTime)
print(type(sniffTime))
输出:
821693000 nanoseconds
<class 'numpy.timedelta64'>
错误
AttributeError: 'numpy.timedelta64' object has no attribute 'total_seconds'
在线的:
df['PerSec']=df['PerSec'].div(sniffTime.total_seconds())
您可以将 numpy 标量转换为Timedelta
,因此可以使用Timedelta.total_seconds
:
df['PerSec']=df['PerSec'].div(pd.Timedelta(sniffTime).total_seconds())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.