Using Python 3.3, I am trying to fill a NumPy array with contents from a .CSV file. The .CSV file has the following contents:
CellID X Y Z
1230 1 1 0
1231 2 1 0
1232 1 1 1
The first row contains a header and so it must be skipped.
import csv
import numpy as np
csv_fn = "input.csv"
with open(csv_fn, "rb") as infile:
reader = csv.reader(infile)
next(reader, None) # Skips the header?
x = list(reader)
result = np.array(x).astype("int") # Converts to a matrix of int?
The variable result doesn't seem to contain the expected values. I've tried to query the dimension using result.shape.
How do I fix this code so it reads the contents into the array?
skiprows = 1? Or genfromtxt