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 8866189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:43:33+00:00 2026-06-14T16:43:33+00:00

I am dealing with a dataset where observations occur between opening and closing hours

  • 0

I am dealing with a dataset where observations occur between opening and closing hours — but the service closes on the day after it opens. For example, opening occurs at 7am and closing at 1am, the following day.

This feels like a very common problem — I’ve searched around for it and am open to the fact I might just not know the correct terms to search for.

For most of my uses it’s enough to do something like:

   open_close = pd.DatetimeIndex(start='2012-01-01 05:00:00', periods = 15, offset='D')

Then I can just do fun little groupbys on the df:
df.groupby(open_close.asof).agg(func).

But I’ve run into an instance where I need to grab multiple of these open-close periods. What I really want to be able to do is just have an DatetimeIndex where I get to pick when an day starts. So I could just redefine ‘day’ to be from 5AM to 5AM. The nice thing about this is I can then use things like df[df.index.dayofweek == 6] and get back everything from 5AM on Sunday to 5AM on Monda.

It feels like Periods…or something inside of pandas anticipated this request. Would love help figuring it out.

EDIT:

I’ve also figured this out via creating another column with the right day
df['shift_day'] = df['datetime'].apply(magicFunctionToFigureOutOpenClose)
— so this isn’t blocking my progress. Just feels like something that could be nicely integrated into the package (or datetime…or somewhere…)

  • 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-14T16:43:35+00:00Added an answer on June 14, 2026 at 4:43 pm

    Perhaps the base parameter of df.resample() would help:

    base : int, default 0
        For frequencies that evenly subdivide 1 day, the "origin" of the
        aggregated intervals. For example, for '5min' frequency, base could
        range from 0 through 4. Defaults to 0
    

    Here’s an example:

    In [44]: df = pd.DataFrame(np.random.rand(28),
    ....:           index=pd.DatetimeIndex(start='2012/9/1', periods=28, freq='H'))
    
    In [45]: df
    Out[45]: 
                                0
    2012-09-01 00:00:00  0.970273
    2012-09-01 01:00:00  0.730171
    2012-09-01 02:00:00  0.508588
    2012-09-01 03:00:00  0.535351
    2012-09-01 04:00:00  0.940255
    2012-09-01 05:00:00  0.143483
    2012-09-01 06:00:00  0.792659
    2012-09-01 07:00:00  0.231413
    2012-09-01 08:00:00  0.071676
    2012-09-01 09:00:00  0.995202
    2012-09-01 10:00:00  0.236551
    2012-09-01 11:00:00  0.904853
    2012-09-01 12:00:00  0.652873
    2012-09-01 13:00:00  0.488400
    2012-09-01 14:00:00  0.396647
    2012-09-01 15:00:00  0.967261
    2012-09-01 16:00:00  0.554188
    2012-09-01 17:00:00  0.884086
    2012-09-01 18:00:00  0.418577
    2012-09-01 19:00:00  0.189584
    2012-09-01 20:00:00  0.577041
    2012-09-01 21:00:00  0.100332
    2012-09-01 22:00:00  0.294672
    2012-09-01 23:00:00  0.925425
    2012-09-02 00:00:00  0.630807
    2012-09-02 01:00:00  0.400261
    2012-09-02 02:00:00  0.156469
    2012-09-02 03:00:00  0.658608
    

     

    In [46]: df.resample("24H", how=sum, label='left', closed='left', base=5)
    Out[46]: 
                                 0
    2012-08-31 05:00:00   3.684638
    2012-09-01 05:00:00  11.671068
    
    In [47]: df.ix[:5].sum()
    Out[47]: 0    3.684638
    
    In [48]: df.ix[5:].sum()
    Out[48]: 0    11.671068
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large dataset that I am dealing with in Python. It is
When dealing with a collection of key/value pairs is there any difference between using
thank you for your patience. I am dealing with a large dataset detailing patients
Dealing with a Thread safe object - for example : Cache Object Msdn states
Currently I am dealing with a large dataset and some queries are executing several
Dealing with some legacy code and in trying to get a poorly designed database
Dealing with Java - which the option you prefer in the most cases -
When dealing with a series of numbers, and wanting to use hash results for
When dealing with a single file, I'm used to: /blah do some work n
When dealing with events, people are usually taking examples of very simple values object

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.