Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 930
Kay Avatar asked Nov 13 '16 19:11

Kay


People also ask

How do I change the format of a column in pandas?

to_numeric() The best way to convert one or more columns of a DataFrame to numeric values is to use pandas. to_numeric() . This function will try to change non-numeric objects (such as strings) into integers or floating-point numbers as appropriate.

How Split comma Separated values in pandas DataFrame?

Split column by delimiter into multiple columns Apply the pandas series str. split() function on the “Address” column and pass the delimiter (comma in this case) on which you want to split the column. Also, make sure to pass True to the expand parameter.


1 Answers

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.

like image 109
Diego Mora Cespedes Avatar answered Oct 06 '22 07:10

Diego Mora Cespedes