Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7935571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:57:48+00:00 2026-06-03T21:57:48+00:00

I worked now for quite some time using python and pandas for analysing a

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T21:57:50+00:00Added an answer on June 3, 2026 at 9:57 pm

    Here’s an example that does what you want:

    In [32]: from datetime import datetime as dt
    
    In [33]: dr = p.DateRange(dt(2009,1,1),dt(2010,12,31), offset=p.datetools.Hour())
    
    In [34]: hr = dr.map(lambda x: x.hour)
    
    In [35]: dt = p.DataFrame(rand(len(dr),2), dr)
    
    In [36]: dt 
    
    Out[36]: 
    <class 'pandas.core.frame.DataFrame'>
    DateRange: 17497 entries, 2009-01-01 00:00:00 to 2010-12-31 00:00:00
    offset: <1 Hour>
    Data columns:
    0    17497  non-null values
    1    17497  non-null values
    dtypes: float64(2)
    
    In [37]: dt[(hr >= 10) & (hr <=16)]
    
    Out[37]: 
    <class 'pandas.core.frame.DataFrame'>
    Index: 5103 entries, 2009-01-01 10:00:00 to 2010-12-30 16:00:00
    Data columns:
    0    5103  non-null values
    1    5103  non-null values
    dtypes: float64(2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been scratching my head for quite some time now, this code worked fine
It's been quite some time now that I've been coding in C++ and I
Greetings, I've worked on quite a few apps now that are using the MVC
I've been working with branches for quite some time now, but I always used
I have a lot of unmanaged C++ code written quite some time ago. Now,
I've worked myself through the rapidXML sources and managed to read some values. Now
The script below worked on my Mac OS X. I'm now using Ubuntu OS,
Our SVN repository is quite large, and pulling the whole thing takes some time.
I have had some long standing code which has worked fine for quite some
Currently I always worked with GIT and was quite satisfied. Due to some project

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.