In [17]: df
Out[17]:
values
2014-01-01 00:00:00+01:00 1.027799
2014-01-01 01:00:00+01:00 1.579586
2014-01-01 02:00:00+01:00 0.202947
2014-01-01 03:00:00+01:00 -0.214921
2014-01-01 04:00:00+01:00 0.021499
2014-01-01 05:00:00+01:00 -1.368302
2014-01-01 06:00:00+01:00 -0.261738
2014-01-01 22:00:00+01:00 0.808506
2014-01-01 23:00:00+01:00 0.459895
[24 rows x 1 columns]
使用 index 方法asi8
转换为 int64(ns
自 epoch 以来已经存在)这些是 UTC 时间!
In [18]: df.index.asi8//10**6
Out[18]:
array([1388530800000, 1388534400000, 1388538000000, 1388541600000,
1388545200000, 1388548800000, 1388552400000, 1388556000000,
1388559600000, 1388563200000, 1388566800000, 1388570400000,
1388574000000, 1388577600000, 1388581200000, 1388584800000,
1388588400000, 1388592000000, 1388595600000, 1388599200000,
1388602800000, 1388606400000, 1388610000000, 1388613600000])
这些是自纪元以来的本地时区。请注意,这通常不是公共方法,我总是会交换 UTC 数据(如果需要,还可以交换时区)。
In [7]: df.index._local_timestamps()//10**6
Out[7]:
array([1388534400000, 1388538000000, 1388541600000, 1388545200000,
1388548800000, 1388552400000, 1388556000000, 1388559600000,
1388563200000, 1388566800000, 1388570400000, 1388574000000,
1388577600000, 1388581200000, 1388584800000, 1388588400000,
1388592000000, 1388595600000, 1388599200000, 1388602800000,
1388606400000, 1388610000000, 1388613600000, 1388617200000])