I worked now for quite some time using python and pandas for analysing a set of hourly data and find it quite nice (Coming from Matlab.)
Now I am kind of stuck. I created my DataFrame
like that:
SamplingRateMinutes=60
index = DateRange(initialTime,finalTime, offset=datetools.Minute(SamplingRateMinutes))
ts=DataFrame(data, index=index)
What I want to do now is to select the Data for all days at the hours 10 to 13 and 20-23 to use the data for further calculations. So far I sliced the data using
selectedData=ts[begin:end]
And I am sure to get some kind of dirty looping to select the data needed. But there must be a more elegant way to index exacly what I want. I am sure this is a common problem and the solution in pseudocode should look somewhat like that:
myIndex=ts.index[10<=ts.index.hour<=13 or 20<=ts.index.hour<=23]
selectedData=ts[myIndex]
To mention I am an engineer and no programer :) ... yet
In upcoming pandas 0.8.0, you'll be able to write
As it looks messy in my comment above, I decided to provide another answer which is a syntax update for pandas 0.10.0 on Marc's answer, combined with Wes' hint:
Pandas DataFrame has a built-in function pandas.DataFrame.between_time
Create 2 data frames for each period of time:
Data frame you want is merged and sorted df1 and df2:
Here's an example that does what you want: