List Info

Thread: Re: Making table




Re: Making table
user name
2007-03-19 17:52:23
> -----Original Message-----
> From: Kent Johnson [mailto:kent37tds.net]
> Sent: Monday, March 19, 2007 12:59 PM
> To: Carroll, Barry
> Cc: tutorpython.org
> Subject: Re: [Tutor] Making table
> 
> Carroll, Barry wrote:
> >> -----Original Message-----
> >> Date: Mon, 19 Mar 2007 11:53:06 -0400
> >> From: Kent Johnson <kent37tds.net>
> 
> >> Most string formatting conversions allow you
to specify a width
> >> directly. For example,
> >> In [61]: value = 3.45678
> >> In [63]: "%10.3f" % value
> >> Out[63]: '     3.457'
> >>
> >> Kent
> >>
> > What if one wished to align the values in each
column at the decimal
> > point?  Is there a simple means to do this in
Python, or would one
need
> > to write a new function?
> 
> If you specify the number of digits after the decimal
point, that
number
> of digits will always be given, so columns will line
up:
> In [86]: '%10.3f' % 1.2
> Out[86]: '     1.200'
> In [87]: '%10.3f' % 1.23456
> Out[87]: '     1.235'
> 
> If you want something fancier I think you will have to
do it yourself.
> 
> Kent
Kent:

Thanks for your response.  That method is certainly good
enough for
general use.  What about a case where the user needs to keep
track of
significant digits? As an example, assume that the following
values
(pulled arbitrarily from my head, I admit) are accurate to
three
significant digits:

	253.
	77.6
	9.03
	.0210

Using a formatting string of "%10.4f", these would
be rendered as:

	'  253.0000'
	'   77.6000
	'    9.0300'
	'    0.0210'

This formatting gives the impression that all values but the
last are
more precise than they truly are.  A scientist or
statistician would
prefer to see something like this:

	'254.    '
	' 77.6   '
	'  9.03  '
	'  0.0210'

Does numpy or some other math package have that capability?

Thanks again.
 
Barry
barry.carrollpsc.com
541-302-1107
________________________
We who cut mere stones must always be envisioning
cathedrals.

-Quarry worker's creed



_______________________________________________
Tutor maillist  -  Tutorpython.org
http://
mail.python.org/mailman/listinfo/tutor

Re: Making table
country flaguser name
United States
2007-03-20 05:28:24
Carroll, Barry wrote:
> This formatting gives the impression that all values
but the last are
> more precise than they truly are.  A scientist or
statistician would
> prefer to see something like this:
> 
> 	'254.    '
> 	' 77.6   '
> 	'  9.03  '
> 	'  0.0210'
> 
> Does numpy or some other math package have that
capability?

I don't know, I don't use numpy.

Kent
_______________________________________________
Tutor maillist  -  Tutorpython.org
http://
mail.python.org/mailman/listinfo/tutor

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )