Miguel 2488
Miguel 2488

Reputation: 1440

How to specify what comes first when reading time values in pandas (hour, minute, seconds, day, month, year)?

I have the following time data:

0        08/01/16 13:07:46,335437
1        18/02/16 08:40:40,565575
2        14/01/16 22:23:23,606399
3        18/01/16 12:12:46,114231
4        18/01/16 17:09:11,477728
5        20/01/16 12:56:20,432586
6        18/01/16 21:12:53,645333
7        25/01/16 17:29:34,540325
8        16/02/16 10:03:08,698522
9        16/02/16 13:49:54,977352
10       25/02/16 12:17:01,271601

This data is in european time format. (day, month, year). I want to tell pandas to read the dates in that order, the problem is that when i try pd.to_datetime(format = "%d/%m/%Y") it won't work, it says that my data is not in that format, i suppose that this is because i have also the hours minutes and seconds and i'm not telling pandas anything about how to read it. But i can't figure it out.

My question is simple, how can i read my data in this format??

My desired time format is days, month, year, hours, minutes, seconds.

Thank you very much in advance

Upvotes: 3

Views: 79

Answers (1)

jezrael
jezrael

Reputation: 863166

Use parameter format in to_datetime, parameters is possible find in http://strftime.org/:

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

Explanation:

%d - match day  
%m - match month  
%y - match year in format YY  
%H - match hour in 24h format  
%M - match minute  
%S - match second  
%F - match microsecond

Upvotes: 2

Related Questions