[SciPy-user] array indices, column names

Tom Denniston tom.denniston at gmail.com
Sun Oct 26 11:05:38 EDT 2008


There are a number of things to say here:

First, if you want to read directly from .xls files you might want to  
try pyexcelerator.

As I understand it what you are try to do is find what index  
corresponds to the columnames you care about in the larger list of all  
the column names.  If this is the case use numpy.searchsorted.

Finally, you might find it easier to read your info into a recaraay  
using numpy.fromiter and then you will be able to access columns by  
name.

Hope this helps

--Tom


On Oct 25, 2008, at 7:40 AM, Peter Davenport <pwdavenport at gmail.com>  
wrote:

> I want to read in a tab separated data table (from excel), with row  
> and column
> names, then remove or add sets of columns to this table as required.
> The key here is to be able to read in a list of columns that I want  
> to remove,
> rather than doing it one at a time.
>
> I'm a python novice who's dabbled in tcl and perl, I'm trying python  
> and scipy
> since they apparently handle matrixes better.
> I can't find a way of doing this in excel with data filters - hence  
> my attempt
> at python and scipy.
>
> I hope this post is clear, pls tell me if otherwise.
>
> As far as I can see from the scipy cookbook and documentation, my  
> best bet seems
> to be as follows:
>
> To read my table into python from a tab separated txt file and set  
> it as an
> array.
>
>    A = array([[columnnames, a, b, c, d]
>        [row1, 1, 2, 3, 4]
>        [row2, 5, 6, 7, 8]
>        [row3, 9, 10, 11, 12]])
>
> I can then get specific columns using,
>
>    b=A[,0:2]
>
> and presumably it won't be too complex to create new array without  
> these columns
> in a manner such as:
>
>    badcolumns = [1:2:4]
>    c=A[,badcolumns]
>
> My issues is then, how do I turn a list of column names into a list  
> of column
> indices and then remove them from an array?
>
> i.e. starting with a list of column names:
>
>    badcnames = [a,b,d]
>
> how do i get a list of indices:
>
>    badcolumns = [1:2:4]
>
> so that I can then remove them from the array.
>
>
> Any advice greatly appreciated,
>
> Pete
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user



More information about the SciPy-User mailing list