You can keep the column names if you use the names=True
argument in the function np.genfromtxt
data = np.genfromtxt(path_to_csv, dtype=float, delimiter=',', names=True)
Please note the dtype=float
, that will convert your data to float. This is more efficient than using dtype=None
, that asks np.genfromtxt
to guess the datatype for you.
The output will be a structured array, where you can access individual columns by their name. The names will be taken from your first row. Some modifications may occur, spaces in a column name will be changed to _
for example. The documentation should cover most questions you could have.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…