Re: [Tutor] How to calculate high value from multiple lines for each column

2016-02-28 Thread Alan Gauld
On 28/02/16 11:37, Fosiul Alam wrote:

> if i can i just ask you one more favour in related to this qustion.
> 
> for key in values:
> print "svtm-%s ,%s" % (key, max(values[key][0][1:]))
> print "iostat-%s ,%s" % (key, max(values[key][1][1:]))
> 
> 

Sure, what is it?


-- 
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


Re: [Tutor] How to calculate high value from multiple lines for each column

2016-02-28 Thread Fosiul Alam
Thanks Alan
bellow works perfect ..
and thanks you very much for all your support
I just need to do one thing which I should be able to do  my self,
hopefully will be able to finish the whole thing soon.
if i can i just ask you one more favour in related to this qustion.

for key in values:
print "svtm-%s ,%s" % (key, max(values[key][0][1:]))
print "iostat-%s ,%s" % (key, max(values[key][1][1:]))


On Sun, Feb 28, 2016 at 12:30 AM, Alan Gauld 
wrote:

> On 27/02/16 15:46, Fosiul Alam wrote:
>
> > a) Can I combile 2 forloop into one ?
>
> Yes of course.
>
>   for key in values:
>   print "svtm-%s ,%s" % (key, values[key][0])
>   print "iostat-%s ,%s" % (key, values[key][1])
>
>
> > b) How can remove first value from for loop - step a ?
>
> > print "Remove First value", values['dm-30'][0].pop(0)
> > print "SVTM DM30: ", max(values['dm-30'][0])
>
> Instead of using pop() you can use slicing with [1:]:
>
> print "SVTM DM30: ", max(values['dm-30'][0][1:])
> print "IOSTAT DM-30",max(values['dm-30'][1][1:])
>
>
> Does it all in one go.
>
>
> --
> 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


Re: [Tutor] How to calculate high value from multiple lines for each column

2016-02-27 Thread Alan Gauld
On 27/02/16 15:46, Fosiul Alam wrote:

> a) Can I combile 2 forloop into one ?

Yes of course.

  for key in values:
  print "svtm-%s ,%s" % (key, values[key][0])
  print "iostat-%s ,%s" % (key, values[key][1])


> b) How can remove first value from for loop - step a ?

> print "Remove First value", values['dm-30'][0].pop(0)
> print "SVTM DM30: ", max(values['dm-30'][0])

Instead of using pop() you can use slicing with [1:]:

print "SVTM DM30: ", max(values['dm-30'][0][1:])
print "IOSTAT DM-30",max(values['dm-30'][1][1:])


Does it all in one go.


-- 
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


Re: [Tutor] How to calculate high value from multiple lines for each column

2016-02-27 Thread Fosiul Alam
Hi Alan
Thanks for the help.yes now i can see how it working, i am just stick in
small things
so this is what i have done ,

a) Can I combile 2 forloop into one ?
b) How can remove first value from for loop - step a ?


for key in values:
print "svtm-%s ,%s" % (key, values[key][0])

for key in values:
print "iostat-%s ,%s" % (key, values[key][1])
#print data
print "Remove First value", values['dm-30'][0].pop(0)
print "SVTM DM30: ", max(values['dm-30'][0])
print "Remove First VAlue for", values['dm-30'][1].pop(0)
print "IOSTAT DM-30",max(values['dm-30'][1])


output

svtm-dm-30 ,[18.27, 2.0, 0.40002]
svtm-dm-31 ,[18.281, 3.0, 0.69996]
iostat-dm-30 ,[6.3603, 1.0, 0.5]
iostat-dm-31 ,[6.3701, 1.5, 0.59998]
Remove First value 18.27
SVTM DM30:  2.0
Remove First VAlue for 6.36
IOSTAT DM-30 1.0

Thanks for the help.


On Fri, Feb 26, 2016 at 8:12 AM, Alan Gauld 
wrote:

> On 26/02/16 02:36, Fosiul Alam wrote:
> > 1) the final data out put only has  one values  dm-31 but dm-30 is
> > missing.
>
> That's because data is only ever the last iteration of the loop.
> Your output is in values not data.
> Try printing values at the end of the loop.
>
> > 2) I need to assoicated values with dm name example dm-30 and dm-31 as
> > final result .
>
> You are already doing that.
> Its working as expected.
>
> > ['dm-30', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00',
> > '0.00', '0.00', '0.40', '0.50']
> > [[18.27, 2.0], [6.3603, 1.0]]
> > ===
> > ['dm-31', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00',
> > '0.00', '0.00', '0.70', '0.60']
> > [[18.281, 3.0], [6.3701, 1.5]]
>
> Note that the data lines above reflect the correct results for both dm30
> and dm31.
>
> So values is storing both sets of data correctly.
>
> After the loop try:
>
> print "DM30: ", values['dm-30']
> print "DM31:", values['dm-31']
>
>
> HTH,
>
> --
> 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
>
>


-- 
Regards
Fosiul Alam
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to calculate high value from multiple lines for each column

2016-02-26 Thread Alan Gauld
On 26/02/16 02:36, Fosiul Alam wrote:
> 1) the final data out put only has  one values  dm-31 but dm-30 is
> missing.

That's because data is only ever the last iteration of the loop.
Your output is in values not data.
Try printing values at the end of the loop.

> 2) I need to assoicated values with dm name example dm-30 and dm-31 as
> final result .

You are already doing that.
Its working as expected.

> ['dm-30', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00',
> '0.00', '0.00', '0.40', '0.50']
> [[18.27, 2.0], [6.3603, 1.0]]
> ===
> ['dm-31', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00',
> '0.00', '0.00', '0.70', '0.60']
> [[18.281, 3.0], [6.3701, 1.5]]

Note that the data lines above reflect the correct results for both dm30
and dm31.

So values is storing both sets of data correctly.

After the loop try:

print "DM30: ", values['dm-30']
print "DM31:", values['dm-31']


HTH,

-- 
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


Re: [Tutor] How to calculate high value from multiple lines for each column

2016-02-26 Thread Fosiul Alam
Hi Alan

Thanks for the reply, so bellow is the code, hope this is right ,

here 2 issues, i am having , not sure where i am doing wrong. really sorry
if i am doing something very silly .

1) the final data out put only has  one values  dm-31 but dm-30 is missing.
2) I need to assoicated values with dm name example dm-30 and dm-31 as
final result .

Thanks for your help .


for line in dm_data:
fields= line.split()
print fields
data = values.setdefault(fields[0],[ [],[] ]) # return
print data
print "==="
data[0].append(float(fields[10]))
data[1].append(float(fields[11]))
print "--"
print data

bellow is the out put

['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']
[[18.27], [6.3603]]
===
['dm-31', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00',
'0.00', '3.00', '1.50']
[[18.281], [6.3701]]
===
['dm-30', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00',
'0.00', '0.40', '0.50']
[[18.27, 2.0], [6.3603, 1.0]]
===
['dm-31', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00',
'0.00', '0.70', '0.60']
[[18.281, 3.0], [6.3701, 1.5]]
===
--
[[18.281, 3.0, 0.69996], [6.3701, 1.5,
0.59998]]

On Thu, Feb 25, 2016 at 10:04 PM, Alan Gauld 
wrote:

> On 25/02/16 20:44, Fosiul Alam wrote:
> > how ami I gettign the "values" ? as its not defiend
> > anywhere, so how we putting data into variables "values" ?
>
> Look more closely at my previous post.
>
>
> >>> s_value= dict()
> >>> u_value=dict()
> >>>
> >>
> >> You don't need two variables here, just one will do, lets just call it
> >> values.
>
>
> >>   data = values.setdefault(fields[0],[ [],[] ])
> >>   data[0],append(float(fields[10])
> >>   data[1],append(float(fields[11])
>
> HTH
>
> --
> 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


Re: [Tutor] How to calculate high value from multiple lines for each column

2016-02-25 Thread Alan Gauld
On 25/02/16 20:44, Fosiul Alam wrote:
> how ami I gettign the "values" ? as its not defiend
> anywhere, so how we putting data into variables "values" ?

Look more closely at my previous post.


>>> s_value= dict()
>>> u_value=dict()
>>>
>>
>> You don't need two variables here, just one will do, lets just call it
>> values.


>>   data = values.setdefault(fields[0],[ [],[] ]) 
>>   data[0],append(float(fields[10])
>>   data[1],append(float(fields[11])

HTH

-- 
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


Re: [Tutor] How to calculate high value from multiple lines for each column

2016-02-25 Thread Fosiul Alam
Hi Alan
I am little bit confused about the statement,

bellow is from your previuos comments

> if fields[0] in s_value:
> s_value[fields[0]].append(fields[10])
> else:
> s_value[fields[0]]=[fields[10]]
>

We can tidy that up using the setdefault() method:

  data = values.setdefault(fields[0],[ [],[] ]) # return
lists if avail else empty lists
  data[0],append(float(fields[10])
  data[1],append(float(fields[11])

how ami I gettign the "values" ? as its not defiend anywhere, so how we
putting data into variables "values" ?

Thanks fror the help





On Wed, Feb 24, 2016 at 1:06 AM, Alan Gauld 
wrote:

> On 23/02/16 20:33, Fosiul Alam wrote:
> >
> > so there are 2 dm (dm-30 and dm-31) wich 3 sample value
> >
> > dm-30 1.4736.482.820.66   270.84   148.56
> > 240.96 0.06   44.99  18.27   6.36
> > dm-31 1.4736.492.820.66   270.85   148.58
> > 240.94 0.06   45.03  18.28   6.37
> > dm-30 0.00 0.000.000.00 0.00 0.00
> > 0.00 0.000.00   2.00   1.00
> > dm-31 0.00 0.000.000.00 0.00 0.00
> > 0.00 0.000.00   3.00   1.50
> > dm-30 0.00 0.000.000.00 0.00 0.00
> > 0.00 0.000.00   0.40   0.50
> > dm-31 0.00 0.000.000.00 0.00 0.00
> > 0.00 0.000.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
>
> We can do that at the end, just before getting the max().
>
>
> > b) get the max value for clumn 10 and 11 for each dm (dm-30 and dm-31)
> > : I am having to do that
>
> > def _get_io():
> >
> > with open (DM,'r')as f:
> > content=f.readlines()
> > return content
> >
> >
> > s_value= dict()
> > u_value=dict()
> >
>
> You don't need two variables here, just one will do, lets just call it
> values.
>
>
> > if __name__ == '__main__':
> >
> > dm_data=_get_io()
> >
> > for line in dm_data:
> >
>
> You missed the line that split the fields
>
>fields = line.split()
>
>
> > if fields[0] in s_value:
> > s_value[fields[0]].append(fields[10])
> > else:
> > s_value[fields[0]]=[fields[10]]
> >
>
> We can tidy that up using the setdefault() method:
>
>   data = values.setdefault(fields[0],[ [],[] ]) # return
> lists if avail else empty lists
>   data[0],append(float(fields[10])
>   data[1],append(float(fields[11])
>
> See if that gets you closer.
>
> --
> 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
>
>


-- 
Regards
Fosiul Alam
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to calculate high value from multiple lines for each column

2016-02-23 Thread Alan Gauld
On 23/02/16 20:33, Fosiul Alam wrote:
>
> so there are 2 dm (dm-30 and dm-31) wich 3 sample value
>
> dm-30 1.4736.482.820.66   270.84   148.56  
> 240.96 0.06   44.99  18.27   6.36
> dm-31 1.4736.492.820.66   270.85   148.58  
> 240.94 0.06   45.03  18.28   6.37
> dm-30 0.00 0.000.000.00 0.00 0.00
> 0.00 0.000.00   2.00   1.00
> dm-31 0.00 0.000.000.00 0.00 0.00
> 0.00 0.000.00   3.00   1.50
> dm-30 0.00 0.000.000.00 0.00 0.00
> 0.00 0.000.00   0.40   0.50
> dm-31 0.00 0.000.000.00 0.00 0.00
> 0.00 0.000.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

We can do that at the end, just before getting the max().


> b) get the max value for clumn 10 and 11 for each dm (dm-30 and dm-31)
> : I am having to do that

> def _get_io():
>
> with open (DM,'r')as f:
> content=f.readlines()
> return content
>
>
> s_value= dict()
> u_value=dict()
>

You don't need two variables here, just one will do, lets just call it
values.


> if __name__ == '__main__':
>
> dm_data=_get_io()
>
> for line in dm_data:
>

You missed the line that split the fields

   fields = line.split()


> if fields[0] in s_value:
> s_value[fields[0]].append(fields[10])
> else:
> s_value[fields[0]]=[fields[10]]
>

We can tidy that up using the setdefault() method:

  data = values.setdefault(fields[0],[ [],[] ]) # return
lists if avail else empty lists
  data[0],append(float(fields[10])
  data[1],append(float(fields[11])

See if that gets you closer.

-- 
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


Re: [Tutor] How to calculate high value from multiple lines for each column

2016-02-23 Thread Fosiul Alam
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.4736.482.820.66   270.84   148.56
240.96 0.06   44.99  18.27   6.36
dm-31 1.4736.492.820.66   270.85   148.58
240.94 0.06   45.03  18.28   6.37
dm-30 0.00 0.000.000.00 0.00 0.00
0.00 0.000.00   2.00   1.00
dm-31 0.00 0.000.000.00 0.00 0.00
0.00 0.000.00   3.00   1.50
dm-30 0.00 0.000.000.00 0.00 0.00
0.00 0.000.00   0.40   0.50
dm-31 0.00 0.000.000.00 0.00 0.00
0.00 0.000.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 
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.0000
> > (0.0%)   0.000   0.600
> >   0.000   3.000   6.0001
> > (0.0%)   0.300   0.000
> >   3.000   0.000   0.0000
> > (0.0%)   0.000   0.000
> >   5.000   0.000   0.0001
> ...
> >
> > 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


Re: [Tutor] How to calculate high value from multiple lines for each column

2016-02-17 Thread Alan Gauld
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.0000
> (0.0%)   0.000   0.600
>   0.000   3.000   6.0001
> (0.0%)   0.300   0.000
>   3.000   0.000   0.0000
> (0.0%)   0.000   0.000
>   5.000   0.000   0.0001
...
> 
> 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


[Tutor] How to calculate high value from multiple lines for each column

2016-02-17 Thread Fosiul Alam
Hi
I am very new to python, basically , I want to get the Maximum value for
each column

  0.000   0.000   0.0000
(0.0%)   0.000   0.600
  0.000   3.000   6.0001
(0.0%)   0.300   0.000
  3.000   0.000   0.0000
(0.0%)   0.000   0.000
  5.000   0.000   0.0001
(0.0%)   0.200   0.000
  0.000   7.000   3.0000
(0.0%)   0.000   1.000
  0.000   0.000   0.0000
(0.0%)   0.000   0.000
  0.000   0.000   0.0000
(0.0%)   0.000   0.000

So  maximum value for 1st column=5
  maximum value for 2nd column = 7
  maximum value for 3rd colun =6
   ...

How can I do this ?
i will be really greatfull if some give any hits.

Thanks for the help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor