timedelta

pandas Timedelta error

淺唱寂寞╮ 提交于 2020-01-06 10:14:09
问题 I'm getting errors when running the code samples from the pandas documentation. I suspect it might be related to the version of pandas I'm using, but I haven't been able to confirm that. pandas VERSION 0.10.1 numpy VERSION 1.7.0 scipy VERSION 0.12.0.dev-14b1e07 The below examples are taken directly from the pandas documentation here: pandas - Time Deltas This works from datetime import datetime, timedelta from pandas import * s = Series(date_range('2012-1-1', periods=3, freq='D')) s Out[52]:

Using datetime.timedelta to add years

杀马特。学长 韩版系。学妹 提交于 2020-01-03 19:43:07
问题 I am doing some time calculations in Python. Goal: Part of this is trying to : Given a date, add time interval (X years, X months, X weeks), return date ie input args: input_time (datetime.date), interval (datetime.timedelta) return: datetime.date I looked at the datetime and datetime.timedelta docs class datetime.timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)¶. These seem to work well if I want to add a certain number of hours or weeks. However,

How to sleep until a specific time YYYY-MM-DD HH:MM:SS?

爱⌒轻易说出口 提交于 2020-01-03 05:25:27
问题 I have been thinking to do a sleep function where it sleeps until a certain date is called. My idea was based of date such as : 2019-01-20 12:00:00. I haven't really figured out how to start to solve this problem. My idea was something similar such as if there is a date given: time.sleep(until the date and time) So the question is how can I possibly be able to sleep until a certain time given in a value of 2019-01-20 12:00:00? 回答1: Easy, calculate how long it is, and sleep the time. You can

Python's timedelta: can't I just get in whatever time unit I want the value of the entire difference?

本小妞迷上赌 提交于 2019-12-30 16:52:14
问题 I am trying to have some clever dates since a post has been made on my site ("seconds since, hours since, weeks since, etc..") and I'm using datetime.timedelta difference between utcnow and utc dated stored in the database for a post. Looks like, according to the docs, I have to use the days attribute AND the seconds attribute, to get the fancy date strings I want. Can't I just get in whatever time unit I want the value of the entire difference? Am I missing something? It would be perfect if

Python's timedelta: can't I just get in whatever time unit I want the value of the entire difference?

半世苍凉 提交于 2019-12-30 16:50:26
问题 I am trying to have some clever dates since a post has been made on my site ("seconds since, hours since, weeks since, etc..") and I'm using datetime.timedelta difference between utcnow and utc dated stored in the database for a post. Looks like, according to the docs, I have to use the days attribute AND the seconds attribute, to get the fancy date strings I want. Can't I just get in whatever time unit I want the value of the entire difference? Am I missing something? It would be perfect if

Why does it make a difference if I add 1 hour to the UTC time and localize or 1 hour to the local time?

爱⌒轻易说出口 提交于 2019-12-25 18:47:14
问题 Example Code from datetime import datetime, timezone, timedelta import pytz t11 = datetime(1918, 4, 15, 0, 0, tzinfo=timezone.utc).astimezone(pytz.timezone('Europe/Berlin')) t12 = t11 + timedelta(hours=1) t2 = datetime(1918, 4, 15, 1, 0, tzinfo=timezone.utc).astimezone(pytz.timezone('Europe/Berlin')) print(t12) print(t2) Observed 1918-04-15 02:00:00+01:00 1918-04-15 03:00:00+02:00 Expected I expected both to be what I see for t2 . The crucial difference is t2.hour vs t12.hour . For a timezone

Django query : “datetime + delta” as an expression

梦想与她 提交于 2019-12-24 16:25:43
问题 Well, my question is a bit as follows: Suppose I have the next model, this is a simple case: class Period(models.Model): name = CharField(... field specs here ...) start_date = DateTimeField(... field specs here ...) duration = ... don't know what field should i use but this has to hold a delta ... I would like to retrieve objects where (start_date + duration) < now in a django query (i know i can, in python, test like my_date_time + a_time_delta < datetime.now(), but this is not the case ...

How to cast time columns and find timedelta with condition in python pandas

早过忘川 提交于 2019-12-24 09:53:22
问题 I have a column Time which is non null object and I cannot convert it to timedelta or datetime. Time msg 12:29:36.306000 Setup 12:29:36.507000 Alerting 12:29:38.207000 Service 12:29:39.194000 Setup 12:30:05.773000 Alerting 12:30:06.205000 Service 12:32:07.315000 Setup 12:32:17.194000 Service 12:32:26.889000 Setup 12:36:06.274000 Alerting 12:36:08.523000 Service 12:37:59.200000 Setup 12:47:10.652000 Alerting 12:47:43.921000 Setup When I type df.info(), I got that a 'Time' column is non null

Add 24 hours to a negative time difference in python

本小妞迷上赌 提交于 2019-12-23 21:00:04
问题 I am using python to calculate time intervals between two events. Each event has a 'beginning time' and an 'ending time.' I have found the difference between the two in a new column, 'interval', but have negative values when the beginning and ending time are on different days (for instance begin 23:46:00 and end 00:21:00 gives -23:25:00). I would like to create an if-statement to run through the 'interval' column and add 24 hours to any negative values. However, I have had problems with

Pandas date_range - subtracting numpy timedelta gives odd result, time becomes not 0:00:00

主宰稳场 提交于 2019-12-23 14:59:48
问题 I am trying to generate a set of dates with pandas date_range functionality. Then I want to iterate over this range and subtract several months from each of the dates (exact number of month is determined in loop) to get a new date. I get some very odd results when I do this. MVP: #get date range dates = pd.date_range(start = '1/1/2013', end='1/1/2018', freq=str(test_size)+'MS', closed='left', normalize=True) #take first date as example date = dates[0] date Timestamp('2013-01-01 00:00:00',