pandas datetime到unixtime [英] Pandas datetime to unixtime
本文介绍了 pandas datetime到unixtime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将Datetime(2014-12-23 00:00:00)更改为unixtime.我用Datetime函数尝试过,但是没有用.我将Datetime戳记放在一个数组中.
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
非常感谢
推荐答案
我认为您可以减去日期 1970-1-1
以创建 timedelta
,然后访问属性 total_seconds
:
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
这篇关于 pandas datetime到unixtime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文