timedelta

Python command parameter indicating time delta

Python command parameter indicating time delta Question: I need to specify a parameter to a python script indicating time back from now. For example 1d is 1 day from now, 2h is 2 hours from now, 2d3h is 2 days, 3 hours from now. Similar to the journalctl –vacuum-time format (reference). For example, this script …

Total answers: 2

How to calculate differences between two pandas.Timestamp Series in nanoseconds

How to calculate differences between two pandas.Timestamp Series in nanoseconds Question: I have two Series which are pd.Timestamps, and they are extremely close. I’d like to get the elementwise difference between the two Series, but with nanosecond precision. First Series: 0 2021-05-21 00:02:11.349001429 1 2021-05-21 00:02:38.195857153 2 2021-05-21 00:03:25.527530228 3 2021-05-21 00:03:26.653410069 4 2021-05-21 00:03:26.798157366 …

Total answers: 2

Find time difference between two dates in python

Find time difference between two dates in python Question: I am trying to find the time difference between the two given dates in the following format: YYYY-MM-DD HH-MM-SS I have checked the examples, but they use datetime.datetime etc, no specific format of date and time. Asked By: Arseniy Sleptsov || Source Answers: import datetime dt_str_a …

Total answers: 1

Find timedelta difference with DST hours (Python)

Find timedelta difference with DST hours (Python) Question: Given two datetimes such as 2020-01-01 00:00:00 and 2020-04-01 00:00:00, I want to get the timedelta between the two dates in terms of number of hours with any addition/subtraction due to daylight saving time. I am not sure how I can proceed. Asked By: hkbgner || Source …

Total answers: 1

printing Timedelta to nanosecond precision

printing Timedelta to nanosecond precision Question: How can one print directly pandas Timedelta with nanosecond precision? For now, my solution is to add to Timedelta some dummy date to be able to do it. Hopefully, there is a better solution. import pandas as pd time = pd.Timedelta(50400001747113) print(time) # 0 days 14:00:00.001747 print(pd.Timestamp(‘2019-10-02’) + time) …

Total answers: 4

How to fix OverflowError: Overflow in int64 addition

How to fix OverflowError: Overflow in int64 addition Question: I’m trying to subtract column df[‘date_of_admission’] from the column df[‘DOB’] to find the difference between then and store the age value in df[‘age’] column, however, I’m getting this error: OverflowError: Overflow in int64 addition DOB date_of_admission age 2000-05-07 2019-01-19 12:26:00 1965-01-30 2019-03-21 02:23:12 NaT 2018-11-02 18:30:10 …

Total answers: 6

Round time to nearest hour python

Round time to nearest hour python Question: I was trying to round off time to the nearest hour in python in a dataframe. Suppose if a timestamp is 2017-11-18 0:16 it should come as 2017-11-18 0:00 and 2017-11-18 1:56 should round off as 2017-11-18 2:00 Asked By: user123 || Source Answers: This is one way. …

Total answers: 5

How to efficiently add seconds place to date time

How to efficiently add seconds place to date time Question: I have a pandas data frame full of 1 second data of the form “10/23/2017 6:00”. Each time appears 60 times in the file, and I’d like to know if there is an easy/efficient/smart way to add seconds to each row such that I get …

Total answers: 1

How Do I Format a pandas timedelta object?

How Do I Format a pandas timedelta object? Question: I am using pandas timedelta objects to keep track of split times in a sports related data set using the following sort of construction: import pandas as pd pd.to_timedelta(“-0:0:1.0”) This natively reports as: -1 days +23:59:59 I can get the raw seconds count using pd.to_timedelta(“-0:0:1.0”).total_seconds() but …

Total answers: 3