Reputation: 1046
I have a data frame like this:
0 0.131567
1 0.098878
2 0.102000
. ...
94574 0.088912
94575 0.089399
and I know it corresponds to some time interval eg. 15:57:32 - 16:50:05. So I would like to convert indexes from sequence of number to sequence of timestamps. So that output will look like this
15:57:32.000000 0.131567
15:57:32.031000 0.102000
... ...
16:50:04.969000 0.088912
16:50:04.000000 0.089399`
Perhaps I can do it with the following code:
> rng = date_range('15:57:32.000000','16:50:04.000000' , freq=??)
> ts = Series(data, index=rng)
But how should I choose frequency then? Are there any other way to do it or I am on the right path?
Upvotes: 0
Views: 135
Reputation: 18658
you can specify a multiplier in the freq field. help(pd.date_range)
gives :
freq : string or DateOffset, default 'D' (calendar daily) Frequency strings can have multiples, e.g. '5H'
rng = pd.date_range('15:57:32','16:50:04',freq='33328us')
Then len(rng)
is exactly 94576
:
2016-03-15 15:57:32 0.881135
2016-03-15 15:57:32.033328 0.237618
2016-03-15 15:57:32.066656 0.761269
....
2016-03-15 16:50:03.962272 0.820865
2016-03-15 16:50:03.995600 0.181762
Upvotes: 1