Hello Anton,
I just had the same problem and came up with the following solution:
a = csv2rec(fname) # read a csv file into a
a[a.dtype.names[5]] # access column 6 (index 5) in the file
As a shorthand you could assign the column names to another field in the
recarray:
a.cols = a.dtype.names
a
The recarrays were what csv2rec is returning and that's why I was using it. And
this afternoon was the first time I was hearing about red arrays so I was
trying to get my stuff done with the wrong tool. I've changed my code to use
regular txt file loading and all works great.
Thanks everybody f
Pierre GM wrote:
> Note also that you are not limited to recarrays: you can use what's
> called a flexible-type arrays, which still gives the possibility to
> access individual fields by keys, without the overload of recarrays
> (where fields can also be accessed as attributes). For example:
FYI, I recoded np.loadtxt to handle missing data, automatic name
definition and conversion functions, as a merge of np.loadtxt and
mlab.csv2rec. You can access the code here:
https://code.launchpad.net/~pierregm/numpy/numpy_addons
Hopefully these functions will make it to numpy at one point or
You're right! I read more about recarrays and they were built specially for
being called by the column name, so I shouldn't have used csv2rec from the
start!
Thanks for the quick responses!
Anton
Patrick Marsh-2 wrote:
>
> In my limited opinion, numpy's loadtxt is the way to go. Loadtxt
> d
In my limited opinion, numpy's loadtxt is the way to go. Loadtxt
doesn't care about the headerYou can read in the arrays like this:
# read in all 5 columns as text
col1, col2, col3, col4, col5 = np.loadtxt(filename, dtype=dtype, unpack=True)
or if you want to skip the column headings and read in
I am plotting the data in those csv files and the forst 4 columns in the
files have the same title but the 5th has the name based on the date and
time so it would be unique in each of the files. As I have about 600 files
to batch process, adjusting my script manually is not an option.
The way I h
I'm not sure what you are needing it for, but I would suggest looking
into numpy's loadtxt function. You can use this to load the csv data
into numpy arrays and pass the resulting arrays arround.
-Patrick
On Sat, Jan 3, 2009 at 11:21 AM, antonv wrote:
>
> Hi all,
>
> I have a lot of csv fi
Hi all,
I have a lot of csv files to process, all of them with the same number of
columns. The only issue is that each file has a unique column name for the
fourth column.
All the csv2rec examples I found are using the r.column_name format to
access the data in that column which is of no use fo