arrays - Python Assigning CSV File to a Variable -


my task import csv file , make array, have done. task assign data variable- possible? instance, how go accessing 2nd column array typing in myvariablename[1] ?

import csv import numpy np f = open("test.csv") csv_f = csv.reader(f) row in csv_f:     print(np.array(row)) f.close() 

you can use numpy.loadtxt().

a.csv:

1,2,3 4,5,6 7,8,9 

code:

import numpy np  matrix = np.loadtxt(open("a.csv","rb"),delimiter=",") print(matrix[:,1]) # prints [ 2.  5.  8.] 

Comments