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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:56:14+00:00 2026-06-18T06:56:14+00:00

I am trying to go through every row in a DataFrame index and remove

  • 0

I am trying to go through every row in a DataFrame index and remove all rows that are not between a certain time.

I have been looking for solutions but none of them separate the Date from the Time, and all I want to do is drop the rows that are outside of a Time range.

  • 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-18T06:56:15+00:00Added an answer on June 18, 2026 at 6:56 am

    You can use the between_time function directly:

    ts.between_time(datetime.time(18), datetime.time(9), include_start=False, include_end=False)
    

    Original answer:

    You can use the indexer_between_time Index method.

    For example, to include those times between 9am and 6pm (inclusive):

    ts.ix[ts.index.indexer_between_time(datetime.time(9), datetime.time(18))]
    

    to do the opposite and exclude those times between 6pm and 9am (exclusive):

    ts.ix[ts.index.indexer_between_time(datetime.time(18), datetime.time(9),
                                        include_start=False, include_end=False)]
    

    Note: indexer_between_time‘s arguments include_start and include_end are by default True, setting include_start to False means that datetimes whose time-part is precisely start_time (the first argument), in this case 6pm, will not be included.

    Example:

    In [1]: rng = pd.date_range('1/1/2000', periods=24, freq='H')
    
    In [2]: ts = pd.Series(pd.np.random.randn(len(rng)), index=rng)
    
    In [3]: ts.ix[ts.index.indexer_between_time(datetime.time(10), datetime.time(14))] 
    Out[3]: 
    2000-01-01 10:00:00    1.312561
    2000-01-01 11:00:00   -1.308502
    2000-01-01 12:00:00   -0.515339
    2000-01-01 13:00:00    1.536540
    2000-01-01 14:00:00    0.108617
    

    Note: the same syntax (using ix) works for a DataFrame:

    In [4]: df = pd.DataFrame(ts)
    
    In [5]: df.ix[df.index.indexer_between_time(datetime.time(10), datetime.time(14))]
    Out[5]: 
                                0
    2000-01-03 10:00:00  1.312561
    2000-01-03 11:00:00 -1.308502
    2000-01-03 12:00:00 -0.515339
    2000-01-03 13:00:00  1.536540
    2000-01-03 14:00:00  0.108617
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Insert row every X rows in excel I have a large set
I am trying to iterate through a list checking every string in the list
I'm trying to search through many documents and find all instances where an html
I'm trying to retrieve all the rows in a table with children variables where
I am just trying to think through a process I need where I have:
Trying to loop through an array of hashes and getting an error message that
I have been trying to use some snippets on how to delete entire rows
I have a google doc spreadsheet that contains information on every member of a
I have two different things that I'm trying to do. I need to change
I have a table in in which every row contains a form. see below

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.