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?

2

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.