在Python中将String转换为datetime时的ValueError

时间:2015-07-07 16:22:22

标签: python

我有一个Dataframe df,我试图在几个月内找到df['maturity_dt']和今天之间的差异,并使用下面的代码执行此操作,但我收到错误{{1 }}。我想我不知道如何引用ValueError: time data '2015-12-31 00:00:00.0' does not match format '%Y-%b-%d %H:%M:%S'

中的最后一个0
00:00:00.0

谢谢

1 个答案:

答案 0 :(得分:2)

您使用的格式错误,请尝试使用 - %Y-%m-%d %H:%M:%S.%f

%b用于三个月的缩写,例如 - JanFeb等。

最后使用%f微秒。