timedelta

Get the time spent since midnight in dataframe

心已入冬 提交于 2021-01-28 09:52:45
问题 I have a dataframe which has a column of type Timestamp. I want to find the time elapsed (in seconds) since midnight as a new column. How to do it in a simple way ? Eg : Input : samples['time'] 2018-10-01 00:00:01.000000000 2018-10-01 00:00:12.000000000 type(samples['time'].iloc[0]) <class 'pandas._libs.tslib.Timestamp'> Output : samples['time_elapsed'] 1 12 回答1: Note that the date part in each row may be other (not from one and the same day), so you can not take any "base date" ( midnight )

Pandas Timedelta to add decimal hours to existing timestamp

和自甴很熟 提交于 2021-01-28 07:09:49
问题 Aim: I would like to use Timedelta to add hours, in decimal format, to an existing timestamp. My current code is giving me an issue - probably because I don't know how to not create a list (been struggling for a while on how to address things). Heh. I have a dataframe named 'df' that looks roughly like the following: +---------------------+----------+ | Time | AddHours | +---------------------+----------+ | 2019-11-13 09:30:00 | 3.177481 | | 2019-11-13 09:30:00 | 2.752435 | | 2019-11-13 09:30

Aggregate in django with duration field

谁说我不能喝 提交于 2021-01-28 04:38:41
问题 My model is: class Mo(Model): dur = DurationField(default=timedelta(0)) price_per_minute = FloatField(default=0.0) minutes_int = IntegerField(default=0) # dublicates data from dur , only for test Some test data: for i in range(4): m = Mo(dur=timedelta(minutes=i), minutes_int=i, price_per_minute=10.0) m.save() I want to multiply the dur by price_per_minute and find Sum : r = Mo.objects.all().aggregate(res=Sum(F('dur')*F('price_per_minute'))) print(r['res']/(10e6 * 60)) but: Invalid connector

python timedelta behaviour on subtraction

末鹿安然 提交于 2021-01-27 02:26:06
问题 This question originated when I came upon (another thread) about python's datetime and timedelta instances I followed the update by jimgardener and read the comments by eyquem ,and tried out some python code ..I am having a bad time understanding the way things work here(due to my newbie to python status)..I thought it was proper to ask a new question import datetime #for t1=23:30:00 PM t1 = datetime.time(23,30,00) #for t1=00:15:30 AM t2 = datetime.time(0,15,30) td1 = datetime.timedelta(hours

Pandas - combine row dates with column times

半腔热情 提交于 2020-12-11 08:57:52
问题 I have a dataframe: Date 0:15 0:30 0:45 ... 23:15 23:30 23:45 24:00 2004-05-01 3.74618 3.58507 3.30998 ... 2.97236 2.92008 2.80101 2.6067 2004-05-02 3.09098 3.84625 3.54672 ... 2.83725 2.93876 2.82762 2.6255 How do I convert it to: Date value 2004-05-01 0:15 3.74618 2004-05-01 0:30 3.58507 2004-05-01 0:45 3.30998 ... I wrote some code which does work, but I'm sure it's possible to do the same in more elegant couple of lines code cols = [] for col in frame.columns.values: if col != '24:00': dt