Home > Blockchain >  How to calculate minutes passed since given date
How to calculate minutes passed since given date

Time:04-26

I have a dataframe that has a column named Created_Timestamp. I want to see how many minutes passed since that given date. I want to know dwell time in minutes from the column Created_Timestamp.

 Created_Timestamp          Dwell Time
 2022-04-25 00:33:33.482      842 min 
 2022-04-25 08:30:52.904      364 min 
 2022-04-25 12:11:04.624      144 min

Dwell Time will be from current time.

curtime = dt.now()
df['Dwell Time'] = curtime - df['Created_Timestamp']

This did not work as I intended. How can I do this correctly?

CodePudding user response:

import pandas as pd
from datetime import datetime

curtime = datetime.now()

qqq = pd.to_datetime(df['Created_Timestamp'])
aaa = pd.to_datetime(curtime)
ttt = (aaa - qqq).dt.total_seconds()/60
df['Dwell Time'] = ttt

Output

         Created_Timestamp  Dwell  Time   Dwell Time
0  2022-04-25 00:33:33.482    842  min   1463.694005
1  2022-04-25 08:30:52.904    364  min    986.370305
2  2022-04-25 12:11:04.624    144   min   766.174972
  • Related