简体   繁体   中英

How do I find the difference in time between yesterday and today in pandas?

I want to find out how much time as passed from last night to today morning. What is the quickest way to do this? The format of the pandas dataframe is shown here. format

If the datatype is not already datetime, you can use this:

from datetime import datetime
frm = '%H:%M'  #format
delta = datetime.strptime(df['wake_time'][row_number], frm) - datetime.strptime(df['sleep_time'][row_number], frm)

*assuming your pandas dataframe is named df and the row index is row_number

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM