如何将 DataFrame 行转换为日期时间格式?

How to convert from DataFrame row to datetime format?

我有以下df

0    05/08/2013 16:04:02:155
1    05/08/2013 16:04:02:170
2    05/08/2013 16:04:02:217
3    10/07/2013 16:40:51:787
4    07/24/2014 09:50:30:228
Name: ctimestamp, dtype: object

我需要转换为日期时间

df['ctimestamp'] = pd.to_datetime(df['ctimestamp'])

但是我有这个错误

raise ParserError("Unknown string format: %s", timestr)
dateutil.parser._parser.ParserError: Unknown string format: 05/08/2013 16: 04: 02: 155
make: *** [test] Error 1

您需要为您的字符串指定日期格式,因为它不是最流行的格式:

pd.to_datetime(df['ctimestamp'], format="%m/%d/%Y %H:%M:%S:%f")

这会起作用。