genfromtxt to structured array

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

genfromtxt to structured array

Timmie
Administrator
Hello,
this may be a easier question.

I want to load data into an structured array with getting the names from the
column header (names=True).

The data looks like:
   
    ;month;day;hour;value
    1995;1;1;01;0

   
but loading only works only if changed to:
   
    year;month;day;hour;value
    1995;1;1;01;0


How do I read in the original data?

Thanks,
Timmie

_______________________________________________
NumPy-Discussion mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: genfromtxt to structured array

Ryan May-3
On Fri, Sep 25, 2009 at 4:30 PM, Timmie <[hidden email]> wrote:

> Hello,
> this may be a easier question.
>
> I want to load data into an structured array with getting the names from the
> column header (names=True).
>
> The data looks like:
>
>    ;month;day;hour;value
>    1995;1;1;01;0
>
>
> but loading only works only if changed to:
>
>    year;month;day;hour;value
>    1995;1;1;01;0
>
>
> How do I read in the original data?

There's an assumption that the number of names is the same as the
number of columns.  You can just specify the names and skip reading
the names from the file:

numpy.genfromtext(filename, delimiter=';', skiprows=1, names=['year',
'month', 'day', 'hour', 'value'])

Ryan

--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
Sent from Norman, Oklahoma, United States
_______________________________________________
NumPy-Discussion mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/numpy-discussion