python - convert date from numpyarray into datetime type -> getting mystic error -


I load a file f with the numpy.loadtxt function this type I and to remove some of the dates was on a format: 15.08 - 21.08.2011

  numpyarr = loadtxt (f, dtype = str, delimiter = ";", skiprows = 1) alldate = numpyarr [:, 0] [0] data = Datetime.datetime.strptime (alldate, "% d.% M -% d.% M% y")  < / Pre> 

And here is the full error:

Traceback (most recent call final): File "C: \ Pithan \ Test DATETIME_2.py", line 52, & lt ; Module & gt; Dat = datetime.datetime.strptime (aldate, "% d.% M -% d.% M %% y") file "C: \ Python 27 \ lib \ _strptime.py", line 308, in _strktima format_regex = _TimeRE_cache .compile (format) file "C: \ Python27 \ lib \ _strptime.py", line 265, re_compile compilation returns (self.pattern (format), IGNORECASE) file "C: \ Python27 \ lib \ re.py" line 1 9 0, compile returns _compile (pattern, flags) file "C: \ Python 27 \ in lib \ re.py", line 242, _compile raise error, v # invalid expression sre_constants.error: group name as the 'D' Definition group 3; Group 1

Is anyone's idea?

A day-to-day holds the same date & amp; Time, while in your field contains two dates and tricks to remove them in the same variable, in particular, the error you are getting is because you have % d and % m Used twice.

You can try something:

  a = datetime.datetime.strptime (alldate.split ('-') [0], "% d.% M. ") B = datetime.datetime.strptime (Bye split ('-') [1],"% d.% M %% Y ") a = datetime.datetime (b. Year, one month, one. Day)  

(This is not the best code, but it shows the fact that there are two dates in two different formats hidden in your string).


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -