[SciPy-user] loadtxt error
David Huard
david.huard at gmail.com
Wed Apr 23 15:35:35 EDT 2008
You can use loadtxt's converters:
>From numpy SVN, here is the docstring:
converters : {}
A dictionary mapping column number to a function that will convert
that
column to a float. Eg, if column 0 is a date string:
converters={0:datestr2num}. Converters can also be used to provide
a default value for missing data: converters={3:lambda s: float(s or
0)}.
David
2008/4/23, Dharhas Pothina <Dharhas.Pothina at twdb.state.tx.us>:
>
>
> Ok it looks like I had a couple of rows with values missing in the third
> column. I didn't notice before since matlab and octave assumes zeros in
> those cases. Is there a function in numpy/scipy that can read files like
> that or should I fix the file before reading it in?
>
> thanks for your help.
>
> - dharhas
>
> >>> Pauli Virtanen <pav at iki.fi> 4/23/2008 9:50 AM >>>
>
> Wed, 23 Apr 2008 16:44:16 +0200, Nils Wagner wrote:
>
> > On Wed, 23 Apr 2008 09:31:06 -0500
> > "Dharhas Pothina" <Dharhas.Pothina at twdb.state.tx.us>
> > wrote:
> [clip]
> >> I have an ascii text file with the format :
> >>
> >> year month sumprcp(in)
> >> 1976 01 2.07
> >> 1976 02 0.76
> >> 1976 03 2.53
> >> 1976 04 2.25
> >> ...
> >>
> >> When trying to read it with the function loadtxt() I am
> >>getting an error :
> >> in iPython I type :
> >>
> >> from numpy import *
> >> year,month,data =
> >>loadtxt('portarthurcity_monthlyprecip.txt',skiprows=1,unpack=True)
> >>
> >> I get the error :
>
> No problem here either, with numpy 1.0.4. Is there garbage later on in
> the file?
>
> --
> Pauli Virtanen
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20080423/b5f1be59/attachment.html>
More information about the SciPy-User
mailing list