Search code examples
pythonarraysnumpyimportgenfromtxt

python numpy import of uneven (data missing) array


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.


Solution

  • Skip the first row by using the argument skiprows=1 in np.loadtxt or np.genfromtxt.