timedelta

How to convert timedelta in data frame to datetime

How to convert timedelta in data frame to datetime Question: I have couple columns in df with avg time, example "0 days 00:00:21". I want convert all columns to datetime.time format "hh:mm:ss" without "0 days". How can I do this? my df Asked By: Grzegorz Z || Source Answers: not sure how you data is …

Total answers: 2

Convert string that was originally a `timedelta` back into a `timedelta` object in Python

Convert string that was originally a `timedelta` back into a `timedelta` object in Python Question: I have strings which were originally produced from timedelta objects like so: print(f'{my_delta}’). I have many of these statements logged (e.g. "12:21:00", "1 day, 0:53:00", "2 days, 9:28:00") and I simply want to parse these logged statements to convert back …

Total answers: 3

Select previous row from the given parameters

Select previous row from the given parameters Question: I have a data frame that looks like this: id code date 1 37 2022-01-11 1 22 2021-10-01 1 39 2019-02-11 1 21 2018-10-08 1 17 2018-09-19 1 18 2018-09-10 1 39 2017-03-20 1 36 2017-02-28 1 34 2017-02-14 1 31 2017-01-20 1 21 2016-11-17 1 17 …

Total answers: 1

how to calculate time between two datetime in python?

how to calculate time between two datetime in python? Question: I have two datetime as below start=2023/04/05 08:00:00, end=2023/04/05 16:00:00 I want to get time by lTime = start + (end – start) /3 or lTime = (start * 2 + end) /3 I used code as below lTime = start + timedelta(end – start) …

Total answers: 1

How to convert 'YYYY-mm-dd HH:MM:SS.[]' to number of minutes in the date?

How to convert 'YYYY-mm-dd HH:MM:SS.[]' to number of minutes in the date? Question: I have a dataframe df with column date in format ‘YYYY-mm-dd HH:MM:SS.miliseconds’ (datetime64[ns]). I want to generate another column, minutes (float), as the number of minutes counted from time 00:00:00 to time HH:MM:SS. How can I do that? Asked By: NigelBlainey || …

Total answers: 2

How to filter on dates n days from from today using Python

How to filter on dates n days from from today using Python Question: iI am fairly new to Python and have not used datetime/timedelta too much, I am trying to look at a dataset I have from the past 90 days and I have seen how to get todays date, but have no clue how …

Total answers: 1

Timedelta only shows 2 digits in some cases

Timedelta only shows 2 digits in some cases Question: I got the following lines of code: from datetime import datetime def my_function(): start_time = datetime.now() # Do something end_time = datetime.now() return (end_time – start_time).microseconds print(my_function) If the function executes "slow enough", I manage to get output like 906 or 1021. But sometimes, if I …

Total answers: 1

How to add time to a type datetime64

How to add time to a type datetime64 Question: I have a dataframe which has a column named DEPARTURE. It is a datetime64 type that says the date and time of a departure. I also have a column named ACTUAL_ELAPSED_TIME which is the amount of minutes the flight took as an integer. I would like …

Total answers: 1

Wrong time delta calculation in python datetime package

"Wrong" time delta calculation in python datetime package Question: What value do you expect to be 26-Mar-2023 8AM Amsterdam time – 25-Mar-2023 8AM Amsterdam time? Day-light-saving is on since 26-Mar-2023 in Amsterdam, so 25-Mar is in UTC+1 and 26-Mar is in UTC+2, intuitively either 23 hours or 25 hours, but not 24 hours because of …

Total answers: 1