On Sat, May 9, 2009 at 8:35 PM, Evan Mason <evanma...@gmail.com> wrote:

> Hi, I want to use mlab.load to load in some data:
>
>
>        1) 2004/02/27 21:51:00           1     2553.51     2553.51
> -99.0000N      3.217
>        2) 2004/02/27 22:01:00           2     2553.47     2553.47
> -99.0000N      3.217
>        3) 2004/02/27 22:10:59           3     2553.45     2553.45
> -99.0000N      3.218
>        4) 2004/02/27 22:20:59           4     2553.46     2553.46
> -99.0000N      3.223
>
>
> unfortunately missing values are given as -99.000N, and these cause the
> following error:
>
>
> In [98]: mlab.load(site_file,skiprows=29,usecols=[4])
> ---------------------------------------------------------------------------
> ValueError                                Traceback (most recent call last)
>
> /Users/evan/python/tools/fig_NEA_seas_paper_RAPID.py in <module>()
> ----> 1
>       2
>       3
>       4
>       5
>
> /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/mlab.pyc
> in load(fname, comments, delimiter, converters, skiprows, usecols, unpack,
> dtype)
>    1458         if usecols is not None:
>    1459             vals = splitfunc(line)
> -> 1460             row = [converterseq[j](vals[j]) for j in usecols]
>    1461         else:
>    1462             row = [converterseq[j](val)
>
> ValueError: invalid literal for float(): -99.00N
>
>
> Is there any way around this, apart from editing all the data files to
> remove every 'N'?


Make use of the converters argument:

mlab.load(..., converters={5:fix_func})

Where fix_func is a function that will convert the -99.0000N values to what
you're looking for.

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image 
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to