datetime

How to count concurrent events in a dataframe in one line?

天涯浪子 提交于 2021-02-04 16:08:19
问题 I have a dataset with phone calls. I want to count how many active calls there are for each record. I found this question but I'd like to avoid loops and functions. Each call has a date , a start time and a end time . The dataframe: start end date 0 09:17:12 09:18:20 2016-08-10 1 09:15:58 09:17:42 2016-08-11 2 09:16:40 09:17:49 2016-08-11 3 09:17:05 09:18:03 2016-08-11 4 09:18:22 09:18:30 2016-08-11 What I want: start end date activecalls 0 09:17:12 09:18:20 2016-08-10 1 1 09:15:58 09:17:42

Converting date string with timezone to epoch

泄露秘密 提交于 2021-02-04 16:08:18
问题 I'm trying to convert this date string including timezone to epoch time. (python 2.7) Mon, 08 Jun 2009 19:37:51 GMT I tried to do so like that: from dateutil import parser parser.parse("Mon, 08 Jun 2009 19:37:51 GMT").strftime('%s') The error I get is: ValueError: Invalid format string What is the problem? How can it be fixed? Thanks. 回答1: Python 3.5 solution using timestamp() method: from dateutil import parser print(parser.parse("Mon, 08 Jun 2009 19:37:51 GMT").timestamp()) which yields:

Converting date string with timezone to epoch

二次信任 提交于 2021-02-04 16:07:42
问题 I'm trying to convert this date string including timezone to epoch time. (python 2.7) Mon, 08 Jun 2009 19:37:51 GMT I tried to do so like that: from dateutil import parser parser.parse("Mon, 08 Jun 2009 19:37:51 GMT").strftime('%s') The error I get is: ValueError: Invalid format string What is the problem? How can it be fixed? Thanks. 回答1: Python 3.5 solution using timestamp() method: from dateutil import parser print(parser.parse("Mon, 08 Jun 2009 19:37:51 GMT").timestamp()) which yields:

Converting date string with timezone to epoch

点点圈 提交于 2021-02-04 16:06:52
问题 I'm trying to convert this date string including timezone to epoch time. (python 2.7) Mon, 08 Jun 2009 19:37:51 GMT I tried to do so like that: from dateutil import parser parser.parse("Mon, 08 Jun 2009 19:37:51 GMT").strftime('%s') The error I get is: ValueError: Invalid format string What is the problem? How can it be fixed? Thanks. 回答1: Python 3.5 solution using timestamp() method: from dateutil import parser print(parser.parse("Mon, 08 Jun 2009 19:37:51 GMT").timestamp()) which yields:

Reliable way to detect if a column in a data.frame is.POSIXct

孤人 提交于 2021-02-04 14:22:05
问题 R has is.vector , is.list , is.integer , is.double , is.numeric , is.factor , is.character , etc. Why is there no is.POSIXct , is.POSIXlt or is.Date ? I need a reliable way to detect POSIXct object, and class(x)[1] == "POSIXct" seems really... dirty. 回答1: I would personally just use inherits as joran suggested. You could use it to create your own is.POSIXct function. # functions is.POSIXct <- function(x) inherits(x, "POSIXct") is.POSIXlt <- function(x) inherits(x, "POSIXlt") is.POSIXt <-

Extracting Only Year Value in Crystal Report DateTime Field

只愿长相守 提交于 2021-02-04 13:46:11
问题 I am working with Crystal Report, right now I am in a situtation where I have to extract only Year value from a datetiem field, for example, if the value is : 01/03/2014 10:20:01AM I only need to extract 2014 I did what is that , I changed the DataFormat of the field is dd/mm/yyyyy Now i hav eapplied formula on it. Formula = Right(CStr ({report;1.FirstYearDate}),4) It shows 01AM Kindly help me out 回答1: Here I have done with this way, my string was "01/02/2012 10:45:22Am" after using this

Extracting Only Year Value in Crystal Report DateTime Field

江枫思渺然 提交于 2021-02-04 13:45:00
问题 I am working with Crystal Report, right now I am in a situtation where I have to extract only Year value from a datetiem field, for example, if the value is : 01/03/2014 10:20:01AM I only need to extract 2014 I did what is that , I changed the DataFormat of the field is dd/mm/yyyyy Now i hav eapplied formula on it. Formula = Right(CStr ({report;1.FirstYearDate}),4) It shows 01AM Kindly help me out 回答1: Here I have done with this way, my string was "01/02/2012 10:45:22Am" after using this

python pandas merge multiple csv files

ぃ、小莉子 提交于 2021-02-04 13:14:28
问题 I have around 600 csv file datasets, all have the very same column names [‘DateTime’, ‘Actual’, ‘Consensus’, ‘Previous’, ‘Revised’], all economic indicators and all-time series data sets. the aim is to merge them all together in one csv file. With ‘DateTime’ as an index. The way I wanted this file to indexed in is the time line way which means let’s say the first event in the first csv dated in 12/18/2017 10:00:00 and first event in the second csv dated in 12/29/2017 09:00:00 and first event

python default parameter value using datetime

倖福魔咒の 提交于 2021-02-04 13:09:26
问题 I have a simple Python script that uses a signal handler for Ctl-C. If the program completes normally, the end time is passed into the "print_results" function. I wanted the print_results function to have an optional parameter that, if not passed, simply gets the current "now" time. But when I call it from the signal handler, it does not get the correct time. Here is my simplified, but reproducible, program: import sys import signal import urllib2 import urllib import datetime import time

Pandas datetime to unixtime

不打扰是莪最后的温柔 提交于 2021-02-04 12:28:25
问题 I want to change Datetime (2014-12-23 00:00:00) into unixtime. I tried it with the Datetime function but it didn´t work. I got the Datetime stamps in an array. Zeit =np.array(Jahresgang1.ix[ :,'Zeitstempel']) t = pd.to_datetime(Zeit, unit='s') unixtime = pd.DataFrame(t) print unixtime Thanks a lot 回答1: I think you can subtract the date 1970-1-1 to create a timedelta and then access the attribute total_seconds: In [130]: s = pd.Series(pd.datetime(2012,1,1)) s Out[130]: 0 2012-01-01 dtype: