Questions tagged [timedelta]
Timedelta refers to the difference between two timestamps, which is a measure of elapsed time. It may also specifically refer to the 'timedelta' type in Python.
936
questions
2
votes
1answer
38 views
How to calculate the average periode duration of date series with panda?
I would like to calculate the mean periode duration for the occurrence of different events.
I got data where every event has an id and is tracked in a single line identified by its id. every time an ...
-5
votes
1answer
37 views
Arithematic operation among multiple hour minute strings [Pythonic Way] [closed]
Below is the problem description:
We have 3 strings with format 'HH:MM'.
Example: n1= '15:30', n2 = '04:30', n3 = '06:00'
We want to find S where S can be any one of the all possible arithmetic ...
1
vote
4answers
54 views
Add hours with datetime.timedelta(hours=1)
I saw in a related post that you cant add with .timedelta less than 24 hours but i need to really add a hour to my time, my code is this:
Hour =df['Hour'].values[0]
16:42:00
The column Hour is a ...
0
votes
0answers
13 views
Duration with datetime.time objects: subtraction of datetime.time elements in datafame [duplicate]
I have a data frame with two columns representing the departure and arrival times of an aircraft. Each element in these columns is datetime.time object. Each column e.g. df['CRS_ARR_TIME'] is series ...
1
vote
2answers
60 views
Subtracting a string converted into a datetime object
I have a piece of code, which takes inputs in 24 hour time such as 23:59, and prints how much time is left, so if it was 11:59 in the morning, it would return 12 hours.
I have been able to do this so ...
1
vote
1answer
21 views
Python Timedelta[M] adds incomplete days
I have a table that has a column Months_since_Start_fin_year and a Date column. I need to add the number of months in the first column to the date in the second column.
DateTable['Date']=DateTable['...
1
vote
1answer
23 views
Subtract datetime now from a dataframe column without Saturday and Sunday
Currently my script is subtracting my current time with the times that i have in a Dataframe column called "Creation", generating a new column with the days of the difference. I get the ...
0
votes
0answers
31 views
How to get queryset with total seconds from sum of DurationField
Suppose, I have a Django model called MyModel like this:
class MyModel(models.Model):
event_started = models.DateTimeField(default=timezone.now)
event_duration = models.DurationField()
Now I ...
0
votes
1answer
52 views
Python calculated Timedelta 50 years in future, should be same day
This is a follow up to Calculating new column value in dataframe based on next rows column value
The solution in the previous question worked for a column holding hh:mm:ss values as a string.
I tried ...
0
votes
0answers
29 views
pandas Timedelta doesn't recognize month intervals as string (`3M` or `P3M`)
I want to convert a string (3M, 3d, etc.) to timedelta in pandas.
The function to do this is pandas.Timedelta. It works fine with:
>>> pandas.__version__
'1.1.5'
>>> pandas.Timedelta(...
3
votes
1answer
32 views
How to convert X min, Y sec string to timestamp
I have a dataframe with a duration column of strings in a format like:
index
duration
0
26 s
1
24 s
2
4 min, 37 s
3
7 s
4
1 min, 1 s
Is there a pandas or strftime() / strptime() way to convert ...
0
votes
2answers
44 views
Add and Subtract Dates Python
I only have datetime, timedelta and date modules in my python. Unfortunately I’ll not be able to use relativedelta to simply add months and years easily.
I would need some advice in adding months and ...
0
votes
1answer
34 views
Time delta for each element between two elements in a list
I am trying to get the delta time between each two datetime elements in a list. But every time I try something i get an index error or the values are incorect.
Out of the list I am facing negative ...
1
vote
1answer
32 views
Python's humanize timedelta() tells me that minimum_unit is an invalid argument?
I am trying to print the approximate time difference between two dates. In the really well answered question here: Format timedelta to string several answers were given, and I can use one of those to ...
3
votes
1answer
41 views
Sum DataFrame Columns without Dropping Columns
I have this dataframe:
>>> d = pd.DataFrame(
{ "a": [1,1]
, "b": [2,2]
, "c": [4,5]
, "d": [pd.Timedelta(hours=6),pd.Timedelta(hours=7)]
, "e&...
0
votes
0answers
37 views
How do I display a timedelta in the format HH:MM:SS on my Plotly Express line chart's axis?
I want to plot a continuous 'Time' column against dates on a simple timeseries linechart in plotly express. The 'Time' columm starts out as a string, in the format HH:MM:SS, but when I plot this ...
0
votes
0answers
18 views
Show s-precise interval when doing to_timedelta on ns-precise interval in pandas? [duplicate]
>>>interval_in_nano_seconds = 12987846139 # about 13 seconds
>>>my_timedelta = pd.to_timedelta(interval_in_nano_seconds , unit='ns')
>>>print(my_timedelta)
0 days 00:00:12....
2
votes
1answer
57 views
Creating rows as per duration using datetime JULIA
I am facing an issue to write a code using datetime. I had created a scenario I am working on. Can someone help me out on the code in JULIA.
Input:
Name, Channel, Duration, Start_time
John, A, 2, 16:...
3
votes
1answer
34 views
Convert TimedeltaIndex to DatetimeIndex
I'm trying to extract times from a TimedeltaIndex object.
I tried using pd.to_datetime() but got the following error:
>>> import pandas as pd
>>> times = pd.timedelta_range(start='10:...
2
votes
3answers
40 views
Timedelta time difference expressed as float variable
I have data in a pandas dataframe that is marked by timestamps as datetime objects. I would like to make a graph that takes the time as something fluid. My idea was to substract the first timestamp ...
0
votes
1answer
30 views
datetime.datetime + timedelta(days=5) is returning None
startdate = dt.strptime('13/12/2020', '%d/%m/%Y')
enddate = dt.strptime('4/12/2020', '%d/%m/%Y')
interval = 5
print('startdate', startdate)
print('enddate', enddate)
loop_startdate = startdate
...
1
vote
1answer
24 views
Keeping track of how many observations fall within a fixed time window when time delta is not constant
I have a dataframe with observations indexed by time, but the time delta between observations is not constant.
df
>>>
TimeStamp x1 x2
1 2015-03-01 19:05:01 0.812 ...
0
votes
0answers
32 views
Replacing NaNs with date and time format
I'm working with the following dataframes.
Date Light (umols) Time_difference
0 2018-01-12 07:16:52 2.5 NaT
1 2018-01-12 07:19:52 4.9 0 days 00:03:00
2 2018-01-12 07:22:52 4.9 0 days 00:...
1
vote
1answer
17 views
Comparing timedelta fields
I am looking at file delivery times and can't work out how to compare two timedelta fields using a for loop if statement.
time_diff is the difference between cob_date and last_update_time
average_diff ...
-2
votes
1answer
27 views
Hello! I need help wich datetime [duplicate]
I wrote this code:
chegada = input('Enter arrival time: "Hours: Minutes" ')
saida = input('Inform the time of departure: "Hours: Minutes" ')
fmt = '%H:%M'
tdelta = datetime....
0
votes
1answer
34 views
convert object to datetime . time format more than 24 hours
I got data that the time format include some rows that the time is more than 24 hours.
the data also incluse date parameter
time 26:00 mean the day after at 2:00
max time is 28:00
I want to create ...
0
votes
1answer
26 views
Trying to change Timedelta to 0
I have the following dataframe with timedeltas:
0 -1 days +10:53:56
1 1 days 10:13:53
2 0 days 00:28:00
3 0 days 01:21:00
4 0 days 00:19:00
5 -1 days +23:59:59
6 ...
1
vote
1answer
53 views
Python Pandas Working with Timedelta then saving it to csv
I am trying to transition my reports that are currently automated with VBA to python.
But since i work with lots of durations on my exports I have a problem.
If i want to do some measures with this ...
0
votes
1answer
52 views
In Python,Excel,Pandas, I Need to move row based on Date to new sheet, but getting date error
so I have an excel report that is run weekly that we manually modify. I have created a Python scrip to remove unwanted data and format it. No I have a request that I need to copy data that is 1 year ...
1
vote
3answers
39 views
How pass dynamic arguments to the datetime.timedelta function?
I'm working on a python3 script where I use timedelta() function and need to pass parameters (keyword arguments with values) to timedelta() dynamically.
I tried several things but I can't figure out ...
0
votes
1answer
34 views
How to transform a 5 digit format to %Y-%d-%m in python?
So i have a column "Date" that holds dates in a 5 digit format. i´m trying to create a new column with the format i want (%Y-%d-%m), but the loop show below just don´t stops.
for u in df[&...
0
votes
0answers
20 views
How to fill out missing entries with zeroes in a dataset using pandas and numpy? [duplicate]
I have a dataset with a 1-second timestep in the form of a CSV with the following format:
2021-02-07 11:00:30, 64.8
2021-02-07 11:00:31, 64.8
2021-02-07 11:00:35, 50.3
..
..
and so on and so ...
0
votes
2answers
41 views
How to subtract two date columns and the result being a positive integer only
Employee ID Name Leave From Leave To Leave Days
10107 Habib 2020-10-31 2020-01-11 -293 days +00:00:00
I want to extract the total no. of leave days for every employee by ...
0
votes
1answer
48 views
Conversion of integer values into days in pandas
How do I convert the datatype of a column from integer to timedelta days format? I tried doing it but got the following error.
new_monthly5['APPROVED LEAVES'] = new_monthly5['APPROVED
LEAVES']+...
-1
votes
1answer
14 views
Questions about Python3 timedate module
I have a quick question about a little snippet of code I've written and I have run into a little problem.
I have created a program I want to run for exactly one hour, then exit it self.
This does not ...
2
votes
2answers
53 views
Add date to an DataArray of float (or viceversa)
I'm kind of new in python. I have an xarray DataArray which contains a variable made of floats. These floats are supposed to be seconds. I would like to add these floats to a given date:
2021-01-01 00:...
0
votes
1answer
31 views
Pandas using Datetimeindex and loc
I'm using loc to get the indices under certain conditions. Then I take timedeltas of those indices and try to access my dataframe again with those two indices. I get the following error:
"Cannot ...
0
votes
0answers
34 views
Games Since in last win python pandas
Date HomeTeam isWin
10/23/2015 United 1
01/04/2016 United 0
03/25/2016 United 1
04/14/2016 United 1
04/14/2016 Turk 1
04/15/2016 Turk 1
I ...
0
votes
0answers
14 views
How can I skip Saturdays and Sundays, while having 3 episodes per day?
I'm writing code to automate the process of adding video production credits to a website. Right now my episodes progress and my date progresses with each episode. I need for the date to only progress ...
0
votes
0answers
36 views
Remove similar records with times within one hour of each other
I have an Excel file containing calls with various timestamps and other data. Example below:
ID Date Time Call Number Report Number Location
00 2020-12-01 15:47:00 ...
0
votes
1answer
21 views
How to calculate time-delta between (row 1 and 2) and (row 3 and 4) and so on?
I have the dataset,
ID Date
1 12/12/2020 13:00
1 12/12/2020 14:00
1 12/12/2020 15:00
1 12/12/2020 16:00
2 12/13/2020 13:00
2 12/13/2020 13:15
2 12/13/2020 14:00
2 12/13/2020 14:30
...
-2
votes
2answers
91 views
Hours and time converting to a certain format [closed]
I have been trying to change the following format of time 8.25 (fractional hours) to 8.15 meaning 8:15. And 17.75 to 17.45 meaning 17:45. The problem is that I specifically need that format (timedelta)...
0
votes
3answers
68 views
Python get months start and end dates for a given year
I want to write a python function to get months start and end dates for a given year.
Sample Input : 2021
Expected output :
[(01-Jan-2021,31-Jan-2021), (01-Feb-2021,28-Feb-2021), (01-Mar-2021,31-Mar-...
3
votes
3answers
61 views
sum up all the time delta values in a dictionary
I have a dictionary with time delta values.
{1: Timedelta('0 days 01:44:39'),
2: Timedelta('0 days 02:34:01'),
3: Timedelta('0 days 00:49:15'),
4: Timedelta('0 days 01:13:26'),
5: Timedelta('0 ...
1
vote
1answer
47 views
How do I add an average Timedelta to a datetime.time?
I'm trying to impute some missing df['Roll_time'] values I have in my dataset. I have the avg_time_diff variable that is a timedelta64[ns] dtype and the df['Notif_date'] that is a datetime.time.
I ...
1
vote
3answers
46 views
How to get timedelta in seconds from a string? Example: +414 00:45:41.004000
I have data of timedeltas which looks like this:
time_delta = '+414 00:45:41.004000'
So, these values are strings and they are of the format ddd hh:mm:ss.f. I now want to get this deltas to seconds. ...
0
votes
1answer
44 views
python how to round a timestamp by minute? [duplicate]
hey guys im using these 2 functions
def utc_to_local(utc_dt):
return utc_dt.replace(tzinfo=tz.gettz('UTC')).astimezone(tz.gettz('America/New_York'))
def perdelta(start, end, delta):
curr = ...
0
votes
1answer
24 views
seperate on special part of a datetime data and change it to int [duplicate]
I have a dataset like this
data = pd.DataFrame({'order_date-time':['2017-09-13 08:59:02', '2017-06-28 11:52:20', '2018-05-18 10:25:53', '2017-08-01 18:38:42', '2017-08-10 21:48:40','2017-07-27 15:11:...
0
votes
1answer
32 views
Find time difference between two dates in python
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 ...
0
votes
2answers
22 views
How to extract seconds from datetime.timedelta
I have a list of dates and hours. For each date, I would like to extract only the seconds value.
Here is my script :
import datetime
format_string = "%Y-%m-%d %H:%M"
now = datetime.datetime....