0

I have date data in int format with following this insturction: Change date format to int in Python Pandas

Let's assume that that there are 2 different columns : 'Timestamp_start' and 'Timestamp_End'. As the timestamp value is converted in int, how can calculate the time differences between two timestamps in 'minutes' unit?

For example, if the value is formatted in yyyymmddhhss, Timestamp_start is 201911030903 and Timestamp_End is 201911031006. The result might be '63' minutes.

As there are complicated datetime conversions in Python Pandas, I am lost how to calculate the time differences in minutes. The result will be int as well.

1 Answer 1

0

You can use pd.to_datetime for this.

import pandas as pd

ts1 = '201911030903'
ts2 = '201911031006'

sr = pd.Series([ts1, ts2])

sr = pd.to_datetime(sr)

That was just to make a reproducible problem. This gives:

Out[44]: 
0   2019-11-03 09:03:00
1   2019-11-03 10:06:00
dtype: datetime64[ns]

Now onto your problem, just subtract and divide by 60 (seconds):

diff = sr[1] - sr[0]

int(diff.seconds/60)
Out[41]: 63
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.