Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
434 views
in Technique[技术] by (71.8m points)

python - In Pandas, how to convert a string to a datetime object with milliseconds?

I have a column of event's timestamp in my dataframe, looks like "2016-06-10 18:58:25:675", the last 3 digits are milliseconds, is there a efficient way to transform this column to a Pandas datatime type?

When I try:

pd.to_datetime('2016-06-10 18:57:35:317')

An error occurs saying "Unknown string format".

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Something like this should work

pd.to_datetime('2016-06-10 18:57:35:317', format="%Y-%m-%d %H:%M:%S:%f")

You can look up datetime formats here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...