Format a number with commas to separate thousands in Python
To make all your floats show comma separators by default in pandas versions 0.23 through 0.25 set the following:
pd.options.display.float_format = '{:,}'.format
https://pandas.pydata.org/pandas-docs/version/0.23.4/options.html
In pandas version 1.0 this leads to some strange formatting in some cases.
You can use apply() to get the desired result. This works with floating too
import pandas as pdseries1 = pd.Series({'Value': 353254})series2 = pd.Series({'Value': 54464.43})series3 = pd.Series({'Value': 6381763761})df = pd.DataFrame([series1, series2, series3])print(df.head()) Value0 3.532540e+051 5.446443e+042 6.381764e+09df['Value'] = df.apply(lambda x: "{:,}".format(x['Value']), axis=1)print(df.head()) Value0 353,254.01 54,464.432 6,381,763,761.0
df.head().style.format("{:,.0f}")
(for all columns)
df.head().style.format({"col1": "{:,.0f}", "col2": "{:,.0f}"})
(per column)