【发布时间】:2020-07-22 11:40:19
【问题描述】:
我必须解析一个混合格式的日期列:
0 1972-12-31
1 1980-03-31
2 1980-03-31
3 1973-08-31
4 1985-06-28
...
44215 2017 Nov 17
44216 2009-02-13
44217 2018 Jul 3
44218 2011-03-15
44219 2017 Nov 8
Name: publish_time, Length: 44220, dtype: object
我尝试用 pandas 解析它:
pd.datetime.strptime(metadata['publish_time'], '%Y-%m-%d')
但它给了我这个错误:
/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:1: FutureWarning: The pandas.datetime class is deprecated and will be removed from pandas in a future version. Import from datetime instead.
"""Entry point for launching an IPython kernel.
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-83-fa9f0e16e2d9> in <module>()
----> 1 pd.datetime.strptime(metadata['publish_time'], '%Y-%m-%d')
TypeError: strptime() argument 1 must be str, not Series
知道如何解决这个问题吗?
【问题讨论】:
标签: python pandas dataframe date parsing