Parsing scientific notation sensibly?

Google on “scientific notation regexp” shows a number of matches, including this one (don’t use it!!!!) which uses *** warning: questionable *** /[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?/ which includes cases such as -.5e7 and +00000e33 (both of which you may not want to allow). Instead, I would highly recommend you use the syntax on Doug Crockford’s JSON website which … Read more

Display a decimal in scientific notation

from decimal import Decimal ‘%.2E’ % Decimal(‘40800000000.00000000000000’) # returns ‘4.08E+10′ In your ‘40800000000.00000000000000’ there are many more significant zeros that have the same meaning as any other digit. That’s why you have to tell explicitly where you want to stop. If you want to remove all trailing zeros automatically, you can try: def format_e(n): a=”%E” … Read more

Format / Suppress Scientific Notation from Pandas Aggregation Results

Granted, the answer I linked in the comments is not very helpful. You can specify your own string converter like so. In [25]: pd.set_option(‘display.float_format’, lambda x: ‘%.3f’ % x) In [28]: Series(np.random.randn(3))*1000000000 Out[28]: 0 -757322420.605 1 -1436160588.997 2 -1235116117.064 dtype: float64 I’m not sure if that’s the preferred way to do this, but it works. … Read more