I have a .txt array composed of strings and ints. The strings are titles for each column of ints except the first which is just numbering (i.e. 8 columns of string titles at [1:8] and then every other row is 9 columns at [0:8]. I want the numbers and don't need the titles (so if I could import rows [1:,:] that would work fine too). I have been using np.loadtxt() which gives me "ValueError: Wrong number of columns at line 2", have tried using np.genfromtxt() which gives me "Line #2 (got 34 columns instead of 33)" for every row 2 and on.
Asked
Active
Viewed 1,119 times
0
-
I always prefer to use my own parser function. It's not hard to do and you can control everything you need. It's really hard for parsers to figure out what the hell do you keep in your data and guess randomly ah this is a title and this isn't. I'd recommend you write your own and use a try except block in which you try to do the conversion, and if it fails you write the value as a title. Appart from that read [this](http://stackoverflow.com/questions/12319969/how-to-use-numpy-genfromtxt-when-first-column-is-string-and-the-remaining-column) – ljetibo Feb 19 '15 at 01:07
1 Answers
0
Skip the first row by using the argument skiprows=1
in np.loadtxt
or np.genfromtxt
.

Warren Weckesser
- 110,654
- 19
- 194
- 214
-
Yup, this worked perfectly. (must have missed this when I read over the numpy.loadtxt info). Thanks! – user3470496 Feb 19 '15 at 01:23