In [1]:
import numpy as np # get numpy package
data = np.genfromtxt(fname='breakout_data.csv', # data filename
dtype=None, # figure out the data type by column
delimiter=',', # delimit on commas
names=True, # first line contains column namesh
)
Now our data is in a nice numpy ndarray. We can access it using the numpy methods. For example:
We can print the headers and the number of columns...
In [7]:
column_headers = data.dtype.names
print(column_headers) # print the column headers
print('Number of columns: {}'.format(len(column_headers)))
We can also print specific rows of data...
In [3]:
print('The first row of data is: \n{}'.format(data[0])) # print the first row
print('\n') # print a blank line
print('and the last row of data is: \n{}'.format(data[len(data)-1])) # print the last row