I have pandas dataframe in HDFStore with index stored as epoch time. I want to read the data and query based on specific index.
For example - if i have index in datetime64[ns] instead of epoc, i can obtain the result as:
starttime = datetime.datetime(2008,12,22,00,19,55,150000)
start = pd.Timestamp(stoptime) + pd.Timedelta(1)
stoptime = datetime.datetime(2008,12,22,00,55,55,180000)
stop = pd.Timestamp(starttime) + pd.Timedelta(1)
pd.read_hdf('file.h5',columns=['Data','Qty'],where='index > start & index < stop']
How can i achieve the same result if index in HDFStore is stored as epoch time ?
IIUC, you should convert your
start
andstop
times to epoch to be able to perform the query. To do this you can:Then you should be able to perform the query with them. Using your data:
EDIT: more general issues. In case of a numpy
datetime64
object you can first convert it to plaindatetime
:Then you can use the above method.