1

I need to format a series of float to show comma delimitation every 3 digits:

1234567.89123  

should become

1,234,567.89123 

without using:

locale.setlocale(locale.LC_ALL, 'en_US.utf8')

I could convert the float to string and insert commas every three digits starting from left of the decimal dot... Is there a nicer way?

Emanuele
  • 25
  • 1
  • 3
  • Check [this answer](http://stackoverflow.com/a/10742904/6153990). – Sangbok Lee Apr 01 '17 at 14:52
  • Possible duplicate of [How to print number with commas as thousands separators?](http://stackoverflow.com/questions/1823058/how-to-print-number-with-commas-as-thousands-separators) – Farini Apr 01 '17 at 15:10

1 Answers1

2

Refer to this for more information on how to format

s = pd.Series([12345678.9876] * 3)

s.apply('{:,}'.format)

0    12,345,678.9876
1    12,345,678.9876
2    12,345,678.9876
dtype: object

pandas also allows you to set options temporarily with pd.option_context

with pd.option_context('display.float_format', '{:,}'.format):
    print(s)

0   12,345,678.9876
1   12,345,678.9876
2   12,345,678.9876
dtype: float64
piRSquared
  • 285,575
  • 57
  • 475
  • 624