using strpdate2num in load

Hi,

I've a little problem with date conversion. I have a csv file which looks
like :
"Data","Valor"
"15/01/2007"," 6,700012000"
"12/01/2007"," 6,659903000"

"11/01/2007"," 6,701586000"

I try to get date using function strpdate2num in load doing this :

from pylab import datestr2num, load
def comma_nb2float(A):
    return eval(A.replace
(',','.'))
dates, valor =
load("file.csv",delimiter=',',converters={0:strpdate2num('%d/%m/%Y'),1:comma_nb2float},skiprows=1,
usecols=(0,1),unpack=True)

I got the following error message :

<details class='elided'>
<summary title='Show trimmed content'>&#183;&#183;&#183;</summary>

---------------------------------------------------------------------------
exceptions.ValueError Traceback (most recent
call last)

/home/manu/Documents/Perso/....../<ipython console>

/usr/lib/python2.4/site-packages/matplotlib/mlab.py in load(fname, comments,
delimiter, converters, skiprows, usecols, unpack)
   1353 if usecols is not None:
   1354 vals = line.split
(delimiter)
-> 1355 row = [converterseq[j](vals[j]) for j in usecols]
   1356 else:
   1357 row = [converterseq[j](val) for j,val in
enumerate(line.split(delimiter))]

/usr/lib/python2.4/site-packages/matplotlib/dates.py in __call__(self, s)
    182 return value: a date2num float
    183 """
--> 184 return date2num(datetime.datetime(*
time.strptime(s, self.fmt)
[:6]))
    185
    186 def datestr2num(d):

/usr/lib/python2.4/_strptime.py in strptime(data_string, format)
    291 found = format_regex.match(data_string)
    292 if not found:

--> 293 raise ValueError("time data did not match format: data=%s
fmt=%s" %
    294 (data_string, format))
    295 if len(data_string) != found.end():

ValueError: time data did not match format: data="15/01/2007" fmt=%d/%m/%Y

I didn't understood the problem, anyone can help me ?

Try stripping the double quote characters from you file.

JDH

···

On Dec 11, 2007 6:00 AM, Emmanuel <emmanuel@...1321...> wrote:

Hi,

I've a little problem with date conversion. I have a csv file which looks
like :
"Data","Valor"
"15/01/2007"," 6,700012000"
"12/01/2007"," 6,659903000"

"11/01/2007"," 6,701586000"

I try to get date using function strpdate2num in load doing this :

Ok, thank you!

I’m missing an option to (easily) use date that start with the day day/month/year (it is the case in Brazil and France for example)

I’m using something like tha
date_Ymd="%s/%s/%s" % (
datedayfirst.split(’/’)[2],datedayfirst.split(’/’)[1],datedayfirst.split
(’/’)[0])

I was lookigng for sometinh like that :

datestr2num(a,dayfirst=True)
or
datestr2num(a,fmt="%d/%m/%Y")

···

On Dec 11, 2007 11:16 AM, John Hunter <jdh2358@…287…> wrote:

On Dec 11, 2007 6:00 AM, Emmanuel <emmanuel@…1321…> wrote:

Hi,

I’ve a little problem with date conversion. I have a csv file which looks

like :
“Data”,“Valor”
“15/01/2007”," 6,700012000"
“12/01/2007”," 6,659903000"

“11/01/2007”," 6,701586000"

I try to get date using function strpdate2num in load doing this :

Try stripping the double quote characters from you file.

JDH


SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It’s the best place to buy or sell services for
just about anything Open Source.

http://sourceforge.net/services/buy/index.php


Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Hi Emmanuel,
look at dateutil.parser.parse, there is exactly what you search.

···

Le mardi 18 décembre 2007, Emmanuel a écrit :

Ok, thank you!

I'm missing an option to (easily) use date that start with the day
day/month/year (it is the case in Brazil and France for example)

I'm using something like tha
date_Ymd="%s/%s/%s" % (datedayfirst.split('/')[2],datedayfirst.split
('/')[1],datedayfirst.split ('/')[0])

I was lookigng for sometinh like that :

datestr2num(a,dayfirst=True)
or
datestr2num(a,fmt="%d/%m/%Y")

On Dec 11, 2007 11:16 AM, John Hunter <jdh2358@...287...> wrote:
> On Dec 11, 2007 6:00 AM, Emmanuel <emmanuel@...1321...> wrote:
> > Hi,
> >
> > I've a little problem with date conversion. I have a csv file which
>
> looks
>
> > like :
> > "Data","Valor"
> > "15/01/2007"," 6,700012000"
> > "12/01/2007"," 6,659903000"
> >
> > "11/01/2007"," 6,701586000"
> >
> > I try to get date using function strpdate2num in load doing this :
>
> Try stripping the double quote characters from you file.
>
> JDH
>
> -------------------------------------------------------------------------
> SF.Net email is sponsored by:
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
Lionel Roubeyrie - lroubeyrie@...1068...
Chargé d'études et de maintenance
LIMAIR - la Surveillance de l'Air en Limousin
http://www.limair.asso.fr

Yes, I think strpdate2num is based on dateutil.parser.parse thast’s why
I tried dayfirst=True which is used with dateutil.parser.parse.

It would be funny if from a list of string, it could be automatically
try to decide between day/month/year, month/day/year format… (it´s a joke)