Pandas datetime to unixtime

I want to change the Datetime (2014-12-23 00:00:00) to unixtime. I tried it with the Datetime function, but it did not work. I got 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

+6
source share
1 answer

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

 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 
+8
source

All Articles