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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:23:10+00:00 2026-06-18T12:23:10+00:00

I have a pandas DataFrame containing timestamped events. Each event has a start time

  • 0

I have a pandas DataFrame containing timestamped events. Each event has a start time and end time:

start  end other_vars
  100  120  ...
  150  151  ...
  160  170  ...
  200  210  ...

Is there a clean way to calculate time between events (e.g. the span between the end of the previous event and the start of this event) in pandas?

start  end between other_vars
  100  120      NA   ...
  150  151      30   ...
  160  170       9   ...
  200  210      30   ...
  • 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-18T12:23:11+00:00Added an answer on June 18, 2026 at 12:23 pm

    I think the easiest way to accomplish this is to subtract one shifted column from the other. The shift function does exactly that, it shifts an array by a default of one index.

    In [3]: df
    Out[3]:
       start  end
    0    100  120
    1    150  151
    2    160  170
    3    200  210
    
    In [4]: df.start - df.end.shift()
    Out[4]:
    0   NaN
    1    30
    2     9
    3    30
    
    In [5]: df['elapsed'] = df.start - df.end.shift()
    
    In [6]: df
    Out[6]:
       start  end  elapsed
    0    100  120      NaN
    1    150  151       30
    2    160  170        9
    3    200  210       30
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pandas DataFrame containing timestamped events from multiple users. By default, the
Suppose I have a Pandas dataframe df has columns a,b,c,d...z . And I want
I have a pandas DataFrame that has multiple columns in it: Index: 239897 entries,
I am researching/backtesting a trading system. I have a Pandas dataframe containing OHLC data
I have a pandas DataFrame with a date column. It is not an index.
I have the data below saved as a pandas dataframe . With this data,
I have python pandas dataframe, in which a column contains month name. How can
I have the following pandas Dataframe: from pandas import DataFrame, MultiIndex index = MultiIndex.from_tuples(zip([21,22,23],[45,45,46]),
I have a DataFrame with the following structure: <class 'pandas.core.frame.DataFrame'> DatetimeIndex: 3333 entries, 2000-01-03
New to pandas python. I have a dataframe (df) with two columns of cusips.

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.