I would like to create datetime objects from a list of string timecodes like these. However, parse interprets incorrectly for my use case. The list above comes from YouTube’s transcript timecodes. When copied from the site, they use a variable format to designate hours, minutes, and time, based on elapsed time: and parse results in (comments are my interpretations): i.e.
Tag: timedelta
Is there a bug in Python 3.8 datetime with DST transitions?
I’m trying to convert a timezone-aware datetime in Europe/Sofia to the start of the day in Europe/Sofia, but returning the datetime in UTC. Doing this, I encountered a strange problem: Which prints: The bug happens when subtracting the timedelta or doing the replace(), because the result should be midnight in Europe/Sofia with +2 offset, however we’re seeing an incorrect +3
From unix timestamps to relative date based on a condition from another column in pandas
I have a column of dates in unix timestamps and i need to convert them into relative dates from the starting activity. The final output should be the column D, which expresses the relative time from the activity which has index = 1, in particular the relative time has always to refer to the first activity (index=1). Any idea? Answer
how can i calculate the difference between two dates and times in python
my code looks like this: listaDivisa looks like this: I want to calculate how much time (better in minutes) the sensor was ON, I tried doing this: but it doesn’t work, another raw alternative I tried was but, not minding about the fact that it doesn’t even work, I don’t think it could be a smart alternative. How could I
Add timedelta to a date column above weeks
How would I add 1 year to a column? I’ve tried using map and apply but I failed miserably. I also wonder why pl.date() accepts integers while it advertises that it only accepts str or pli.Expr. A small hack workaround is: but this won’t work for months or days. I can’t just add a number or I’ll get a: Most
How to get grouped cumulative duration in pandas?
I have the following data: id encounter_key datetime 1 111 2019-04-14 1 111 2019-04-14 1 111 2019-07-18 1 122 2019-09-02 2 211 2019-10-03 2 211 2020-10-03 I want to find the cumulative duration, grouped by id and encounter_key to achieve the following: id encounter_key datetime cum_duration_days 1 111 2019-04-14 0 1 111 2019-04-14 0 1 111 2019-07-18 95 1 122
How to remove datetime values in a row that are within a certain time relative to another row?
If I have a DataFrame as below: Letter Time 0 x 2021-01-01 14:00:00 1 y 2021-01-01 18:00:00 2 y 2021-01-03 14:00:00 How would I delete a row if a value in the Time column(datetime) is within say 14 hours from the time in the row above? I’ve tried using: but I get KeyError 1 in relation to the line if
Create New Columns Using Multiple Conditions And Time Difference
I have the following dataframe with a tricky problem: I have to make 4 columns (0-90 days, 91-180 days, 181-270 days, 271-360 days) based on the following conditions: Desired output: What would be the smartest way of doing it? Any suggestions would be appreciated. Thanks! Answer You can write a custom function that takes in a list of weights, start
How do I compare a time value to all the time values in a column in pandas?
I want to apply a condition to a column in a dataframe. The column has time values in the format HH:MM:SS and I want to compare it to a fixed time value(threshold), but I am getting errors. Converting the threshold value to datetime.datetime.strptime gives me error. What I want to ask is – In order to compare any two time
python convert timedelta to meaningful string such as “1 hours”
I want to convert a python timedelta object to an easy to read meaningful string for example: any ideas how to do that? Thanks Answer Actually timedelta class, provides you days, seconds, microseconds property directly. But in order to get “hours” and “minutes” you can do some simple calculations yourself. Divide seconds by 60 to get minutes, by 3600 to