ENH: Timestamp/DTI. to epoch time · Issue #14772 · pandas-dev/pandas (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Description
add a .to_epoch(unit='s')
method to Timestamp
and DatetimeIndex
that returns the epoch for that unit. I think would default this to s
as that seems pretty common, but allow any of our units.
In [19]: s = Series(pd.date_range('20160101',periods=3))
In [20]: s
Out[20]:
0 2016-01-01
1 2016-01-02
2 2016-01-03
dtype: datetime64[ns]
In [21]: ((s-Timestamp(0)) / Timedelta('1s')).astype('i8')
Out[21]:
0 1451606400
1 1451692800
2 1451779200
dtype: int64