Skip to content

Commit fddd722

Browse files
committed
DOC: add inverse epoch conversion
1 parent 860d555 commit fddd722

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

doc/source/timeseries.rst

+20-11
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ Return NaT for input when unparseable
247247
Out[6]: DatetimeIndex(['2009-07-31', 'NaT'], dtype='datetime64[ns]', freq=None)
248248
249249
250+
.. _timeseries.converting.epoch:
251+
250252
Epoch Timestamps
251253
~~~~~~~~~~~~~~~~
252254

@@ -279,10 +281,27 @@ Typical epoch stored units
279281

280282
.. ipython:: python
281283
282-
1490195805.433502912
283284
pd.to_datetime([1490195805.433, 1490195805.433502912], unit='s')
284285
pd.to_datetime(1490195805433502912, unit='ns')
285286
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+
286305
.. _timeseries.origin:
287306

288307
Using the Origin Parameter
@@ -306,16 +325,6 @@ Commonly called 'unix epoch' or POSIX time.
306325
307326
pd.to_datetime([1, 2, 3], unit='D')
308327
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-
319328
.. _timeseries.daterange:
320329

321330
Generating Ranges of Timestamps

0 commit comments

Comments
 (0)