Kay
Kay

Reputation: 709

How to convert a numeric column in pandas to a string with comma separators?

I want to convert a column that has values like 1234567.89 to 1,234,567.89. Can someone help me with this.

Upvotes: 19

Views: 21610

Answers (1)

Diego Mora Cespedes
Diego Mora Cespedes

Reputation: 3862

You can format your column by doing this:

df['new_column_name'] = df['column_name'].map('{:,.2f}'.format)

But keep in mind that the new column will contain strings, not floats.

Upvotes: 33

Related Questions