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
296 views
in Technique[技术] by (71.8m points)

python - Pandas: timestamp to datetime

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

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

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]

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

...