Is there a dedicated milli-sec precision timestamp data structure in python pandas? -


for instance, in q, there dedicated time struct, such 11:59:59.999, can use in table column. there in pandas?

i read doc , there seems quite comprehensive examples timestamp on daily resolution, fund managers, guess. there milli-second resolution time struct?

yes there is!

it's called timestamp!

pandas has support nanosecond resolution using own timestamp class subclass of datetime.datetime:

in [6]: pd.timestamp('now') + np.timedelta64(100, 'ns') out[6]: timestamp('2013-10-06 21:09:19.000000100', tz=none)  in [7]: isinstance(_6, datetime.datetime) out[7]: true 

note date-like series objects represented datetime64[ns]:

in [8]: series(date_range('now', periods=5)) out[8]: 0   2013-10-06 21:11:37 1   2013-10-07 21:11:37 2   2013-10-08 21:11:37 3   2013-10-09 21:11:37 4   2013-10-10 21:11:37 dtype: datetime64[ns] 

this true if specify 'd' (day) frequency on construction:

in [11]: series(date_range('1/1/2001', periods=5, freq='d')) out[11]: 0   2001-01-01 00:00:00 1   2001-01-02 00:00:00 2   2001-01-03 00:00:00 3   2001-01-04 00:00:00 4   2001-01-05 00:00:00 dtype: datetime64[ns] 

the values attribute of series yields numpy.ndarray of datetime64[ns] dtype:

in [12]: s = series(date_range('1/1/2001', periods=5, freq='d'))  in [13]: s.values out[13]: array(['2000-12-31t19:00:00.000000000-0500',        '2001-01-01t19:00:00.000000000-0500',        '2001-01-02t19:00:00.000000000-0500',        '2001-01-03t19:00:00.000000000-0500',        '2001-01-04t19:00:00.000000000-0500'], dtype='datetime64[ns]') 

you can create date ranges millisecond frequency (note 'l' here; that's name give milliseconds since 'ms' used monthbegin offset):

in [18]: date_range('2013/11/1', freq='ms', periods=10) out[18]: <class 'pandas.tseries.index.datetimeindex'> [2013-11-01 00:00:00, ..., 2013-11-01 00:00:00.009000] length: 10, freq: l, timezone: none 

in pandas 0.13.0, you'll able create nanosecond ranges date_range, turns out useful data sets sizable sampling rates, e.g., extracellular recordings in neurophysiology:

in [15]: date_range('2013/11/1', freq='n', periods=10) out[15]: <class 'pandas.tseries.index.datetimeindex'> [2013-11-01 00:00:00, ..., 2013-11-01 00:00:00.000000009] length: 10, freq: n, timezone: none 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -