strptime

Formatting Dates in R (Non-standard format)

跟風遠走 提交于 2019-11-28 09:46:28
问题 Not new to R or formatting dates in R and wouldn't be asking this question but I am having seriously strange behavior and in the last 2 hours am no closer to resolving it. I have a dataset which I have imported and want to format the date/time column using as.POSIXct . The date is a non-standard format and I've applied what I know to be the proper formatting. Here is a small part of the data that I am having trouble with. Code just after. Problem is that there are 4 NA's starting at "2015-03

How to parse str(my_datetime) using strptime ?

不打扰是莪最后的温柔 提交于 2019-11-28 08:07:55
问题 This is the default string representation of a datetime: >>> from datetime import datetime, timezone >>> dt = datetime(2017, 1, 1, tzinfo=timezone.utc) >>> print(dt) 2017-01-01 00:00:00+00:00 What is the correct format string to parse that with datetime.strptime ? That is, what goes in place of the '???' to see the following result: >>> from dateutil.parser import parse >>> parse(date_str) == datetime.strptime('???', date_str) True 回答1: Note that str(d) is documented as being equivalent to d

Python -Remove Time from Datetime String

只愿长相守 提交于 2019-11-28 04:22:35
I have a date string and want to convert it to the date type: I have tried to use datetime.datetime.strptime with the format that I want but it is returning the time with the conversion. when = alldates[int(daypos[0])] print when, type(when) then = datetime.datetime.strptime(when, '%Y-%m-%d') print then, type(then) This is what the output returns: 2013-05-07 <type 'str'> 2013-05-07 00:00:00 <type 'datetime.datetime'> I need to remove the the time: 00:00:00. print then.date() What you want is a datetime.date object. What you have is a datetime.datetime object. You can either change the object

R: strptime() and is.na () unexpected results

对着背影说爱祢 提交于 2019-11-28 01:28:40
I have a data frame with roughly 8 million rows and 3 columns. I used strptime() in the following manner: df$date.time <- strptime(df$date.time, "%m/%d/%y %I:%M:%S %p") This works fine for all but 1104 of the rows, which I checked using df[is.na(df$date.time), ] When I look at these "problem" data, the date.time entries seem to be formatted in the way I would expect. For example, here is an observation that comes up as a problem, but doesn't appear to be an NA: id date.time outcome observation543490 2012-03-11 02:14:01 C What could possibly be going on here that is.na(df$date.time) returns a

unknown timezone name in R strptime/as.POSIXct

瘦欲@ 提交于 2019-11-27 22:44:40
Where can I find a list of all legal time names for R function as.POSIXct ? as.POSIXct("1970-01-01",tz="CST") generates a warning that "CST" (Central Standard Time) is unknown. ?Sys.timezone has some hints, specifically to look in: "R_HOME/share/zoneinfo/zone.tab" ( R_HOME is the directory R is installed in). Keep in mind that time zones are nasty and many of their nuances are operating system (and locale?) specific. In your specific case, you want "CST6CDT" instead of "CST" . Timezone stuff can drive you NUTS !! Being located in Germany, this is what I used to do to set my tz: > options(tz=

Converting a string to a formatted date-time string using Python

牧云@^-^@ 提交于 2019-11-27 19:46:17
I'm trying to convert a string "20091229050936" into "05:09 29 December 2009 (UTC)" >>>import time >>>s = time.strptime("20091229050936", "%Y%m%d%H%M%S") >>>print s.strftime('%H:%M %d %B %Y (UTC)') gives AttributeError: 'time.struct_time' object has no attribute 'strftime' Clearly, I've made a mistake: time is wrong, it's a datetime object! It's got a date and a time component! >>>import datetime >>>s = datetime.strptime("20091229050936", "%Y%m%d%H%M%S") gives AttributeError: 'module' object has no attribute 'strptime' How am I meant to convert a string into a formatted date-string? For

datetime.strptime strange behavior [duplicate]

早过忘川 提交于 2019-11-27 08:31:05
问题 This question already has an answer here: Whats wrong with my datetime.strptime format? 1 answer I'm getting the following error on aws virtual machine running python 3.6.8, while on my laptop it works fine with python 3.6.1 return datetime.strptime(date_str, self.date_format) File "/usr/lib64/python3.6/_strptime.py", line 565, in _strptime_datetime tt, fraction = _strptime(data_string, format) File "/usr/lib64/python3.6/_strptime.py", line 362, in _strptime (data_string, format)) ValueError:

AM/PM string is not properly recognized by strptime

Deadly 提交于 2019-11-27 07:51:22
问题 I have encountered something unexpected while working with the function strptime(). The format of the date I have consists of "1/22/2013 11:00:00 P.M" . The format I am using for this is "%m/%d/%Y %I:%M:%S %p". The code is as follows. strptime("1/22/2013 11:00:00 p.m",format="%m/%d/%Y %I:%M:%S %p") [1] NA but if I use strptime("1/22/2013 11:00:00 pm",format="%m/%d/%Y %I:%M:%S %p") [1] "2013-01-22 23:00:00" I get the appropriate result. So does this feature lack in strptime to detect p.m and

Changing date format in R

你。 提交于 2019-11-27 07:07:41
I have some very simple data in R that needs to have its date format changed: date midpoint 1 31/08/2011 0.8378 2 31/07/2011 0.8457 3 30/06/2011 0.8147 4 31/05/2011 0.7970 5 30/04/2011 0.7877 6 31/03/2011 0.7411 7 28/02/2011 0.7624 8 31/01/2011 0.7665 9 31/12/2010 0.7500 10 30/11/2010 0.7734 11 31/10/2010 0.7511 12 30/09/2010 0.7263 13 31/08/2010 0.7158 14 31/07/2010 0.7110 15 30/06/2010 0.6921 16 31/05/2010 0.7005 17 30/04/2010 0.7113 18 31/03/2010 0.7027 19 28/02/2010 0.6973 20 31/01/2010 0.7260 21 31/12/2009 0.7154 22 30/11/2009 0.7287 23 31/10/2009 0.7375 Rather than %d/%m/%Y , I would

Python -Remove Time from Datetime String

依然范特西╮ 提交于 2019-11-27 05:19:27
问题 I have a date string and want to convert it to the date type: I have tried to use datetime.datetime.strptime with the format that I want but it is returning the time with the conversion. when = alldates[int(daypos[0])] print when, type(when) then = datetime.datetime.strptime(when, '%Y-%m-%d') print then, type(then) This is what the output returns: 2013-05-07 <type 'str'> 2013-05-07 00:00:00 <type 'datetime.datetime'> I need to remove the the time: 00:00:00. 回答1: print then.date() What you