Hi Alan Thanks for replying, Yes, I am having some challanges . this is the example file :
so there are 2 dm (dm-30 and dm-31) wich 3 sample value dm-30 1.47 36.48 2.82 0.66 270.84 148.56 240.96 0.06 44.99 18.27 6.36 dm-31 1.47 36.49 2.82 0.66 270.85 148.58 240.94 0.06 45.03 18.28 6.37 dm-30 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 2.00 1.00 dm-31 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 3.00 1.50 dm-30 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.40 0.50 dm-31 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.70 0.60 Basically I am interested with 10 and 11 ( last 2 column) with bellow 2 way a) ignore the firsrt value for each dm ( so line number 1 and 2 will totally ignore) : I am having trouble to do that b) get the max value for clumn 10 and 11 for each dm (dm-30 and dm-31) : I am having to do that I went through this far : - from operator import itemgetter def _get_io(): with open (DM,'r')as f: content=f.readlines() return content s_value= dict() u_value=dict() if __name__ == '__main__': dm_data=_get_io() for line in dm_data: if fields[0] in s_value: s_value[fields[0]].append(fields[10]) else: s_value[fields[0]]=[fields[10]] if fields[0] in u_value: u_value[fields[0]].append(fields[11]) else: u_value[fields[0]]=[fields[11]] print s_value print u_value Python output:= {'dm-30': ['18.27', '2.00', '0.40'], 'dm-31': ['18.28', '3.00', '0.70']} {'dm-30': ['6.36', '1.00', '0.50'], 'dm-31': ['6.37', '1.50', '0.60']} I wanted to combine s_value and u_value with each Max value like bellow {'dm-30': ['2.0', '1.0'], 'dm-31': ['3.0', '1.50']} or just get the Max value for each dm in s_value and u_value like bellow {'dm-30':2.00, 'dm-31': ['3.00]} {'dm-30': [1.00], 'dm-31': [1.50]} Any help will be really appreciable On Wed, Feb 17, 2016 at 10:22 AM, Alan Gauld <alan.ga...@btinternet.com> wrote: > On 16/02/16 22:28, Fosiul Alam wrote: > > Hi > > 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 > lists. > > for line in dataSource: > fields = line.split() > myData[0].append(fields[0]) > myData[1].append(fields[1]) > etc > > 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. > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos > > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > -- Regards Fosiul Alam _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor