Here is an example of data within a csv file “james_test_3.csv”
0.01,10,20,30,40,50,60,70,80,90,100
2,22,32,42,52,62,0.02,82,92,102,112
3,33,999,53,63,73,83,93,4539,113,123
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:
0.02
4539.0
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.
Some, part or all of the information on this page has been learnt from StackOverFlow. Published under Creative Commons License