我有以下形式的日期时间数据:
yyyy-mm-dd hh:minmin:secsec + hh:minmin
例如:2020-02-01 01:00:00 + 01:00
我现在想将其转换为浮点数。我使用了找到该问题的解决方案的函数:python datetime to float with millisecond precision
def datetime_to_float(d):
return d.timestamp()
我使用以下代码将此函数应用于了datetime对象:time_in_float = []
for i in time:
time_in_float.append(i.datetime_to_float())
并得到此错误: ---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-11-f6272033e480> in <module>()
2
3 for i in time:
----> 4 time_in_float.append(i.datetime_to_float())
5
AttributeError: 'datetime.datetime' object has no attribute 'datetime_to_float'
我要在这里更改什么?非常感谢!
最佳答案
您需要在循环中执行time_in_float.append(datetime_to_float(i))
关于python - 如何将datetime对象转换为float? AttributeError : 'datetime.datetime' object has no attribute 'datetime_to_float' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64871345/