【发布时间】:2019-06-04 10:19:53
【问题描述】:
我在 df 中有一个列,其中包含 datetime 字符串,
inv_date
24/01/2008
15/06/2007 14:55:22
08/06/2007 18:26:12
15/08/2007 14:53:25
15/02/2008
07/03/2007
13/08/2007
我使用pd.to_datetime 和%d%m%Y 格式将字符串转换为datetime 值;
pd.to_datetime(df.inv_date, errors='coerce', format='%d%m%Y')
我明白了
inv_date
24/01/2008
0
0
0
15/02/2008
07/03/2007
13/08/2007
格式从inv_date 推断为最常见的日期时间格式;我想知道如何不将15/06/2007 14:55:22、08/06/2007 18:26:12、15/08/2007 14:53:25 转换为 0,而是将15/06/2007、08/06/2007、15/08/2007。
【问题讨论】:
-
pd.to_datetime(df.inv_date.str[:10], errors='coerce', format='%d/%m/%Y')..?
标签: python python-3.x pandas datetime