Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas datetime to unixtime

I want to change Datetime (2014-12-23 00:00:00) into unixtime. I tried it with the Datetime function but it didn´t work. I got the Datetime stamps in an array.

Zeit =np.array(Jahresgang1.ix[ :,'Zeitstempel'])
t = pd.to_datetime(Zeit, unit='s')
unixtime = pd.DataFrame(t)
print unixtime

Thanks a lot

like image 923
A.Boss Avatar asked Dec 02 '15 08:12

A.Boss


1 Answers

I think you can subtract the date 1970-1-1 to create a timedelta and then access the attribute total_seconds:

In [130]:    
s = pd.Series(pd.datetime(2012,1,1))
s

Out[130]:
0   2012-01-01
dtype: datetime64[ns]

In [158]:
(s - dt.datetime(1970,1,1)).dt.total_seconds()

Out[158]:
0    1325376000
dtype: float64
like image 56
EdChum Avatar answered Sep 19 '22 16:09

EdChum