Pandas datetime to unixtime

不打扰是莪最后的温柔 提交于 2021-02-04 12:28:25

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/34038273/pandas-datetime-to-unixtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!