[Tutor] How to calculate high value from multiple lines for each column
alan.gauld at btinternet.com
Wed Feb 17 05:22:03 EST 2016
On 16/02/16 22:28, Fosiul Alam wrote:
> I am very new to python, basically , I want to get the Maximum value for
> each column
> 0.000 0.000 0.000 0
> (0.0%) 0.000 0.600
> 0.000 3.000 6.000 1
> (0.0%) 0.300 0.000
> 3.000 0.000 0.000 0
> (0.0%) 0.000 0.000
> 5.000 0.000 0.000 1
> So maximum value for 1st column=5
> maximum value for 2nd column = 7
> maximum value for 3rd colun =6
> How can I do this ?
The classical way to represent a table of data is using a list of lists
myData = [,,,] # a table with 4 columns
You can then read the data line by line and insert the values into your
for line in dataSource:
fields = line.split()
Then at the end find the max() of each column
for col in myData:
print "Max = " max(col)
There are more efficient ways to do it but that's probably the simplest.
You need to fill in quite a few blanks, such as how you read your data
source - is it a file or what?
Try it and come back if you hit problems.
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:
More information about the Tutor