[Numpy-discussion] data type specification when using numpy.genfromtxt

Benjamin Root ben.root@ou....
Sun Jun 26 14:56:46 CDT 2011

On Sun, Jun 26, 2011 at 2:27 PM, Derek Homeier <
derek@astro.physik.uni-goettingen.de> wrote:

> On 26.06.2011, at 8:48PM, Chao YUE wrote:
> > I want to read a csv file with many (49) columns, the first column is
> string and remaning can be float.
> > how can I avoid type in like
> >
> > data=numpy.genfromtxt('data.csv',delimiter=';',names=True, dtype=(S10,
> float, float, ......))
> >
> > Can I just specify the  type of first cloumn is tring and the remaing
> float? how can I do that?
> Simply use 'dtype=None' to let genfromtxt automatically determine the type
> (it is perhaps a bit confusing that this is not the default - maybe it
> should be repeated in the docstring for clarity that the default is for
> dtype is 'float'...).
> Also, a shorter way of typing the dtype above (e.g. in case some columns
> would be auto-detected as int) would be
> ['S10'] + [ float for n in range(48) ]
Another possibility is -- if you don't want the first column string data --
is to basically ignore that column by specifying the "usecol" parameter.

Ben Root
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20110626/1c30ebf9/attachment.html 

More information about the NumPy-Discussion mailing list