当使用此函数的日期包含tz差异后缀(例如2017-07-17T20:15:03.597144+01:00
)时,核心在执行任何代码之前就会死亡。
如果删除+01:00,脚本将无错运行。
“Pendulum Timestamp”(pdts
)的值为2017-07-17T20:19:14.508636+01:00
系统设置Windows 10 / Spyder 3.1.2 / Python 3.6 / Pandas 0.20.3。我尝试将Pandas更新为0.20.3,但核心仍然死亡。 这是RTFM还是一个bug?感谢
import pendulum as pendulum
import pandas as pd
pendulum_timestamp = pendulum.now()
pdts = pendulum_timestamp
pen_timestamp = pd.to_datetime(pdts)
根据MaxU的要求输出“print(pd.show_versions())”
INSTALLED VERSIONS
------------------
commit: None
python: 3.6.0.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 58 Stepping 9, GenuineIntel
byteorder: little
LC_ALL: None
LANG: en
LOCALE: None.None
pandas: 0.20.3
pytest: 3.0.5
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.25.2
numpy: 1.12.1
scipy: 0.19.0
xarray: None
IPython: 6.0.0
sphinx: 1.5.1
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: 1.2.0
tables: 3.2.2
numexpr: 2.6.2
feather: None
matplotlib: 2.0.2
openpyxl: 2.4.1
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: 0.9.6
lxml: 3.7.2
bs4: 4.5.3
html5lib: None
sqlalchemy: 1.1.5
pymysql: None
psycopg2: None
jinja2: 2.9.4
s3fs: None
pandas_gbq: None
pandas_datareader: 0.4.0
None
答案 0 :(得分:2)
尝试将Pendulum对象强制转换为其字符串表示形式,因为pd.to_timestamp()
并不期望Pendulum对象:
In [91]: import pendulum
In [92]: pdts = pendulum.now()
In [93]: type(pdts)
Out[93]: pendulum.pendulum.Pendulum
In [94]: pd.to_datetime(str(pdts)) # NOTE: pay attention at `str()`
Out[94]: Timestamp('2017-07-17 20:58:08.995228')
In [95]: pdts
Out[95]: <Pendulum [2017-07-17T22:58:08.995228+02:00]>
In [98]: str(pdts)
Out[98]: '2017-07-17T22:58:08.995228+02:00'
In [99]: type(str(pdts))
Out[99]: str