timedelta

Calculating the difference between two Java date instances

谁说我不能喝 提交于 2019-12-17 04:07:41
问题 I'm using Java's java.util.Date class in Scala and want to compare a Date object and the current time. I know I can calculate the delta by using getTime(): (new java.util.Date()).getTime() - oldDate.getTime() However, this just leaves me with a long representing milliseconds. Is there any simpler, nicer way to get a time delta? 回答1: The JDK Date API is horribly broken unfortunately. I recommend using Joda Time library. Joda Time has a concept of time Interval: Interval interval = new Interval

Taking Median of two datetime values or columns

谁都会走 提交于 2019-12-13 18:13:12
问题 For the below data I want to take the middle value or the middle time of the first two timestamps in each row and then subract that third timestamp What would be the best way to take the median value or middle datime of two timestamps? the output expected is in minutes the difference of two timestamps. It is the median or mean of the first two minus the third timestamp. it is the middle value or timestamp of 2018-12-21 23:31:24.615 and 2018-12-21 23:31:26.659 . Once I have that value I want

Parsing an xs:duration datatype into a Python datetime.timedelta object?

耗尽温柔 提交于 2019-12-13 16:18:05
问题 As per the title, I'm trying to parse an XML file containing an xs:duration data type. I'd like to convert that into a Python timedelta object, which I can then use in further calculations. Is there any built-in way of doing this, similar to the strptime() function? If not, what is the best way to achieve this? 回答1: Seeing as I already have a working example of what I asked in the question, I'll post it here for completeness. If any better answers come up I'll accept. period = '-P14D' regex =

Aggregations for Timedelta values in the Python DataFrame

百般思念 提交于 2019-12-12 18:44:12
问题 I have big DataFrame (df) which looks like: Acc_num date_diff 0 29 0:04:43 1 29 0:01:43 2 29 2:22:45 3 29 0:16:21 4 29 0:58:20 5 30 0:00:35 6 34 7:15:26 7 34 4:40:01 8 34 0:56:02 9 34 6:53:44 10 34 1:36:58 ..... Acc_num int64 date_diff timedelta64[ns] dtype: object I need to calculate 'date_diff' mean (in timedelta format) for each account number. df.date_diff.mean() works correctly. But when I try next: df.groupby('Acc_num').date_diff.mean() it raises an exception: "DataError: No numeric

HTML5 Canvas game loop delta time calculations

蹲街弑〆低调 提交于 2019-12-12 15:32:08
问题 I'm new to game development. Currently I'm doing a game for js13kgames contest, so the game should be small and that's why I don't use any of modern popular frameworks. While developing my infinite game loop I found several articles and pieces of advice to implement it. Right now it looks like this: self.gameLoop = function () { self.dt = 0; var now; var lastTime = timestamp(); var fpsmeter = new FPSMeter({decimals: 0, graph: true, theme: 'dark', left: '5px'}); function frame () { fpsmeter

Efficient timedelta calculator

好久不见. 提交于 2019-12-11 15:14:31
问题 I have a time series data from a data logger that puts time stamps (in the form of dates MM--DD-YY HH:MM:SS:xxx:yyy (e.g. --[ 29.08.2018 16:26:31.406 ] --) where xxx and yyy are milliseconds and microseconds respectively) precise up to microseconds when recording data. Now you can imagine that the generated file recorded over a few minutes could be very big. (100s of megabytes). I need to plot a bunch of data from this file vs time in millisconds (ideally). The data looks like below: So I

Trying to get the time delta between two date columns in a dataframe, where one column can possibly be “NaT”

我们两清 提交于 2019-12-11 15:13:32
问题 I am trying to get the difference in days between two dates pulled from a SQL database. One is the start date, the other is a completed date. The completed date can and is, in this case, be a NaT value. Essentially I'd like to iterate through each row, and take the difference, if the completed date is NaT I'd like to skip it or assign a NaN value, in a completely new delta column. the code below is giving me this error: 'member_descriptor' object is not callable for n in df.FINAL_DATE: df

Converting time to a float

若如初见. 提交于 2019-12-11 07:28:58
问题 I wrote a program to compute the hours I've worked but at the end, it returns the value as a time. EX: I worked from 11:45 to 4:30. My program returns 4:45 I would like it to return 4.75. How do I convert this? I am using the following code: import datetime as dt from datetime import timedelta start =(input("Enter start time: " )) end =(input("Enter start time: " )) start_dt = dt.datetime.strptime(start, '%H:%M') end_dt = dt.datetime.strptime(end, '%H:%M') time =(end_dt - start_dt) if time

Pandas: use groupby to count difference between dates

匆匆过客 提交于 2019-12-11 06:18:08
问题 I have df: i,Unnamed,ID,url,used_at,active_seconds,domain,subdomain,search_engine,search_term,diff_time,period 0,322015,0120bc30e78ba5582617a9f3d6dfd8ca,vk.com/antoninaribina,2015-12-31 09:16:05,35,vk.com,vk.com,None,None,,1 1,838267,0120bc30e78ba5582617a9f3d6dfd8ca,vk.com/feed,2015-12-31 09:16:38,54,vk.com,vk.com,None,None,33.0,1 2,838271,0120bc30e78ba5582617a9f3d6dfd8ca,vk.com/feed?section=photos,2015-12-31 09:17:32,34,vk.com,vk.com,None,None,54.0,1 3,322026,0120bc30e78ba5582617a9f3d6dfd8ca

Is there a function in Python/Pandas to get business time Delta between two date times?

时光怂恿深爱的人放手 提交于 2019-12-11 06:05:47
问题 I've got a pandas dataframe with two datetime columns and I would like to calculate the timedelta between the columns in "business minutes". It's easy to add business timedeltas using the offsets method, but I can't seem to find something built in that returns a timedelta in business days, hours, minutes, seconds. I'm very new to Python so it's very likely I'm missing something. Thanks, Nick 回答1: I don't think there's a way in numpy/pandas, but you can do it with python lib businesstime: >>>