将 UTC 时间戳转换为秒 TypeError
Converting UTC timestamps to seconds TypeError
我有以下pandas系列数据::
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
我真的不明白这是怎么回事。
您可以使用 Pandas 日期时间功能:
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。 - 那些 "extra numbers" 只是行号/自动索引 pandas 在您读入数据时分配 :)
我有以下pandas系列数据::
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
我真的不明白这是怎么回事。
您可以使用 Pandas 日期时间功能:
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。 - 那些 "extra numbers" 只是行号/自动索引 pandas 在您读入数据时分配 :)