Here is an example of data within a csv file “james_test_3.csv”
I want to read all of the values in the CSV file but not read the first value of each row. Of those values read, I want to know the highest and lowest value
# take values from a csv file, read all the rows but miss out the # first column of each of those rows, return the highest and lowest # values import numpy array = numpy.genfromtxt('Anaconda3JamesData/james_test_3.csv', delimiter=',') maximum=array[:, 1:].max() minimum=array[:, 1:].min() print (minimum) print (maximum)
The above code returns:
In the code we see
maximum=array[:, 1:].max() minimum=array[:, 1:].min()
This is part of numpy’s array indexing. It is saying take all the row : but miss out the first value of each row (=first value of each column) 1:
Information on numpy’s array indexing can be found here.