timedelta

Convert a column in pandas of HH:MM to minutes

落爺英雄遲暮 提交于 2019-12-23 12:55:22
问题 I want to convert a column in dataset of hh:mm format to minutes. I tried the following code but it says " AttributeError: 'Series' object has no attribute 'split' ". The data is in following format. I also have nan values in the dataset and the plan is to compute the median of values and then fill the rows which has nan with the median 02:32 02:14 02:31 02:15 02:28 02:15 02:22 02:16 02:22 02:14 I have tried this so far s = dataset['Enroute_time_(hh mm)'] hours, minutes = s.split(':') int

Convert a column in pandas of HH:MM to minutes

安稳与你 提交于 2019-12-23 12:55:12
问题 I want to convert a column in dataset of hh:mm format to minutes. I tried the following code but it says " AttributeError: 'Series' object has no attribute 'split' ". The data is in following format. I also have nan values in the dataset and the plan is to compute the median of values and then fill the rows which has nan with the median 02:32 02:14 02:31 02:15 02:28 02:15 02:22 02:16 02:22 02:14 I have tried this so far s = dataset['Enroute_time_(hh mm)'] hours, minutes = s.split(':') int

Calculating the time difference between two times in Java

旧时模样 提交于 2019-12-23 04:58:39
问题 String time1 = br.readLine(); DateFormat sdf = new SimpleDateFormat("hh:mm:ss",Locale.ENGLISH); Date d1 = sdf.parse(time1); int n = Integer.parseInt(br.readLine()); for(int i=0;i<n;i++) { String time2 = br.readLine(); Date d2 = sdf.parse(time2); long diffMs = d1.getTime() - d2.getTime(); System.out.println(diffMs/(1000*60*60)); Input: time1 = 23:05:38 time2 = 12:36:07 Output should be 10 but it’s giving 22 . 回答1: First, I am assuming that the calculation takes place in a time zone without

Pandas Converting an object into timedelta

こ雲淡風輕ζ 提交于 2019-12-22 08:06:22
问题 I have the following data Duration 0 00:00:00 1 00:00:00 2 00:00:57 3 00:03:16 4 00:00:00 And Duration is stored as an object. I would like to convert this into an integer having seconds. for eg 00:03:16 gets converted into 196. I tried various things like astype(timedelta64[s]) but no success. I tried extracting the minutes and seconds and tried converting to integer, that also did not yield results. I am unable to convert the extracted string into an integer. 回答1: in case of series, s.map

Android Studio Mediaplayer how to fade in and out

為{幸葍}努か 提交于 2019-12-22 04:28:18
问题 I am working with the mediaplayer class in android studio. I simply want to fade out one sound and fade in the other sound instead of using setVolume(0,0) and setVolume(1,1). I have created two mediaplayers for this and it seemed like I found a solution in this thread: Android: How to create fade-in/fade-out sound effects for any music file that my app plays? but I don't know how to use deltaTime. There are also some other solutions to this, which I can barely understand. Isn't there an easy

Is there an easy way to convert ISO 8601 duration to timedelta?

白昼怎懂夜的黑 提交于 2019-12-22 01:28:02
问题 Given a ISO 8601 duration string, how do I convert it into a datetime.timedelta ? This didn't work: timedelta("PT1H5M26S", "T%H%M%S") 回答1: I found isodate library to do exactly what I want isodate.parse_duration('PT1H5M26S') 来源: https://stackoverflow.com/questions/36976138/is-there-an-easy-way-to-convert-iso-8601-duration-to-timedelta

Python: Given a Date and Weekday find the date of the next occurrence of a given weekday

爱⌒轻易说出口 提交于 2019-12-21 09:02:51
问题 This is a bit difficult to explain, so I apologize if this doesn't make much sense. I have a program where I am doing some scheduling. One of the settings it has is to run a task weekly on certain days. For example, weekly on Monday, Wednesday and Friday. Consider the example where the current task is scheduled for 1/2/2012, which is a Monday, I already have a bunch of code working to the point where I know the next task run should be on the wednesday following 1/2/2012. All I need to do is

Python 2.6.5: Divide timedelta with timedelta

断了今生、忘了曾经 提交于 2019-12-21 07:04:38
问题 I'm trying to divide one timedelta object with another to calculate a server uptime: >>> import datetime >>> installation_date=datetime.datetime(2010,8,01) >>> down_time=datetime.timedelta(seconds=1400) >>> server_life_period=datetime.datetime.now()-installation_date >>> down_time_percentage=down_time/server_life_period Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand type(s) for /: 'datetime.timedelta' and 'datetime.timedelta' I know this

Finding the mean and standard deviation of a timedelta object in pandas df

馋奶兔 提交于 2019-12-21 03:37:34
问题 I would like to calculate the mean and standard deviation of a timedelta by bank from a dataframe with two columns shown below. When I run the code (also shown below) I get the below error: pandas.core.base.DataError: No numeric types to aggregate My dataframe: bank diff Bank of Japan 0 days 00:00:57.416000 Reserve Bank of Australia 0 days 00:00:21.452000 Reserve Bank of New Zealand 55 days 12:39:32.269000 U.S. Federal Reserve 8 days 13:27:11.387000 My code: means = dropped.groupby('bank')

Differance between two days excluding weekends in hours

安稳与你 提交于 2019-12-20 02:54:27
问题 I have a code that calculates the date differance excluding the weekends using np.busdaycount, but i need it in the hours which i cannot able to get. import datetime import numpy as np df.Inflow_date_time= [pandas.Timestamp('2019-07-22 21:11:26')] df.End_date_time= [pandas.Timestamp('2019-08-02 11:44:47')] df['Day'] = ([np.busday_count(b,a) for a, b in zip(df['End_date_time'].values.astype('datetime64[D]'),df['Inflow_date_time'].values.astype('datetime64[D]'))]) Day 0 9 I need the out put as