我有以下熊猫系列数据:
print(times)
给予
1 2017-07-23T00:26:50Z
3 2017-07-31T04:07:24Z
6 2017-07-18T15:09:20Z
8 2017-07-12T05:24:14Z
...
12353 2017-07-12T18:34:48Z
12355 2017-08-01T22:27:42Z
12356 2017-07-11T03:36:44Z
我只想将这些UTC时间戳转换为秒或
from astropy.time import Time
t = pd.Timestamp(times)
只给出
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-15-320d28559d92> in <module>()
----> 1 t = pd.Timestamp(times)
pandas/_libs/tslibs/timestamps.pyx in
pandas._libs.tslibs.timestamps.Timestamp.__new__()
pandas/_libs/tslibs/conversion.pyx in
pandas._libs.tslibs.conversion.convert_to_tsobject()
TypeError: Cannot convert input [1 2017-07-23T00:26:50Z
我真的不明白发生了什么。
答案 0 :(得分:0)
您可以使用Pandas DateTime功能:
import pandas as pd
import pandas as pd
s=pd.Series(['2017-07-23T00:26:50Z', '2017-07-31T04:07:24Z', '2017-07-18T15:09:20Z', '2017-07-12T18:34:48Z'])
pd.to_datetime(s)
P.S。 -这些“多余的数字”只是读取数据时熊猫分配的行号/自动索引:)