@@ -247,6 +247,8 @@ Return NaT for input when unparseable
247
247
Out[6]: DatetimeIndex(['2009-07-31', 'NaT'], dtype='datetime64[ns]', freq=None)
248
248
249
249
250
+ .. _timeseries.converting.epoch :
251
+
250
252
Epoch Timestamps
251
253
~~~~~~~~~~~~~~~~
252
254
@@ -279,10 +281,27 @@ Typical epoch stored units
279
281
280
282
.. ipython :: python
281
283
282
- 1490195805.433502912
283
284
pd.to_datetime([1490195805.433 , 1490195805.433502912 ], unit = ' s' )
284
285
pd.to_datetime(1490195805433502912 , unit = ' ns' )
285
286
287
+ .. _timeseries.converting.epoch_inverse :
288
+
289
+ From Timestamps to Epoch
290
+ ~~~~~~~~~~~~~~~~~~~~~~~~
291
+
292
+ To invert the operation from above, namely, to convert from a ``Timestamp `` to a 'unix' epoch:
293
+
294
+ .. ipython :: python
295
+
296
+ stamps = pd.date_range(' 2012-10-08 18:15:05' , periods = 4 , freq = ' D' )
297
+ stamps
298
+
299
+ We convert the ``DatetimeIndex `` to an ``int64 `` array, then divide by the conversion unit.
300
+
301
+ .. ipython :: python
302
+
303
+ stamps.view(' int64' ) // pd.Timedelta(1 , unit = ' s' )
304
+
286
305
.. _timeseries.origin :
287
306
288
307
Using the Origin Parameter
@@ -306,16 +325,6 @@ Commonly called 'unix epoch' or POSIX time.
306
325
307
326
pd.to_datetime([1 , 2 , 3 ], unit = ' D' )
308
327
309
- .. note ::
310
-
311
- Without specifying origin the following examples still evaluate, but the results
312
- may be unexpected.
313
-
314
- .. ipython :: python
315
-
316
- pd.to_datetime([1 ])
317
- pd.to_datetime([1 , 3.14 ], unit = ' s' )
318
-
319
328
.. _timeseries.daterange :
320
329
321
330
Generating Ranges of Timestamps
0 commit comments