Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How you create a datetime index in pandas

How do I create an datetime index "foo" to use with raw data series. (Example would "as of" every 15 seconds 'foo' and and every 30 seconds 'foo2'.) If raw series can be inserted into a 'base' dataframe, I would like to use 'foo' to recast the dataframe.

If wanted series to combine combine df "foo" and df "foo2", what would be the memory hits Would it be better to fill the foo index with the raw data series.

EDIT: after import pandas , datetime.timedelta stops working

like image 711
Merlin Avatar asked Dec 21 '25 11:12

Merlin


1 Answers

It's very hard for me to understand what you're asking; an illustration of exactly what you're looking for, with example data, would help make things more clear.

I think what you should do:

rng = DateRange(start, end, offset=datetools.Second(15)

to create the date range. To put data in a DataFrame indexed by that, you should add the columns and reindex them to the date range above using method='ffill':

df = DataFrame(index=rng)
df[colname] = series.reindex(df.index, method='ffill')

Per datetime.timedelta, datetime.datetime is part of the pandas namespace, so if you did from pandas import * then any import datetime you had done before that would be masked by the datetime.datetime reference inside the pandas namespace.

like image 124
Wes McKinney Avatar answered Dec 24 '25 01:12

Wes McKinney



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!