-1

I have the following file:

rowname1     0.0019      0.0142     -0.0258     -0.0058     -0.0097      
rowname2     0.0001      0.0168     -0.0268     -0.0063     -0.0072

and I would like to extract the columns from 2nd (i.e. avoiding the rownames column) to xth. So far I am using the astropy module ascii.read function; if I e.g. set x = 3:

from astropy.io import ascii
x = 3
evec = ascii.read('file', include_names=['col'[i] for i in xrange(2,x)])
print evec

it just returns

<No columns>

How should the for loop be in order to work properly?

Thank you!

Miguel
  • 356
  • 1
  • 15

1 Answers1

1

You have a bug in include_names, i.e. you select the 2nd character of 'col' and do not concatenate the number to the string.

Just replace it with:

evec = ascii.read('file', include_names = ['col' + str(i) for i in xrange(2,x)])

Also consider that the second parameter of xrange is not included; so if you want to include 3 in your example use xrange(2,x+1).

Martin Krämer
  • 567
  • 3
  • 17