13

I have dataframe and column with dates looks like

 date
 1476329529    
 1476329530    
 1476329803 
 1476329805 
 1476329805  
 1476329805 

I use df['date'] = pd.to_datetime(df.date, format='%Y-%m-%d %H:%M:%S') to convert that, but I'm get strange result

 date 
 1970-01-01 00:00:01.476329529   
 1970-01-01 00:00:01.476329530   
 1970-01-01 00:00:01.476329803  
 1970-01-01 00:00:01.476329805    
 1970-01-01 00:00:01.476329805   
 1970-01-01 00:00:01.476329805   

Maybe I did anything wrong

0

2 Answers 2

20

This looks look epoch timestamps which is number of seconds since 1st January 1970 :

In [71]:
pd.to_datetime(df['date'], unit='s')
​
Out[71]:
0   2016-10-13 03:32:09
1   2016-10-13 03:32:10
2   2016-10-13 03:36:43
3   2016-10-13 03:36:45
4   2016-10-13 03:36:45
5   2016-10-13 03:36:45
Name: date, dtype: datetime64[ns]
Sign up to request clarification or add additional context in comments.

2 Comments

Hello, for me this is still defaulting 1970. What is the problem?
check your units. pd now defaults to nanoseconds if you don't specify units
2

Something like this maybe:

import datetime
date = datetime.datetime.fromtimestamp(1476329529)
date
# gives
# datetime.datetime(2016, 10, 13, 5, 32, 9)

str(date) # '2016-10-13 05:32:09'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.