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.

Answer from jeffhale on Stack Overflow
🌐
Mark Needham
markhneedham.com › blog › 2021 › 04 › 11 › pandas-format-dataframe-numbers-commas-decimals
Pandas - Format DataFrame numbers with commas and control decimal places | Mark Needham
April 11, 2021 - This works, but we’ve lost the LTLA Name column and the Population column isn’t formatted how we’d like. Instead of passing a single style to style.format, we can instead pass a dictionary of {"column: "style"}. So to style Population with a comma as thousands separator and PercentageVaccinated with two decimal places, we can do the following:
🌐
Krbnite
krbnite.github.io › HTML-Reports-Those-Numbers-Need-Commas
HTML Reports: Those Numbers Need Commas!
January 17, 2018 - I wish integer-valued columns automatically got commas as well. But, no. That would be too easy. As for the integer variable: pandas doesn’t necessarily care that it’s an integer, but that it’s not a pandas object. Even float(num) would not benefit from setting pandas options. [In] pd.options.display.float_format = '{:,}'.format [In] [In] num = 123456789 [In] df = pd.DataFrame({'num': [123456789.]}) [In] df [Out] num 0 123,456,789.0 [In] [In] num [Out] 123456789 [In] float(num) [Out] 123456789.0
Discussions

python - Format a number with commas to separate thousands - Stack Overflow
I have a large dataframe, which has a column called Lead Rev. This column is a field of numbers such as (100000 or 5000 etc.) I want to know how to format these numbers to show commas as thousand More on stackoverflow.com
🌐 stackoverflow.com
Adding commas to a column in a dataframe
If you're talking about a pandas dataframe, then df['column_name'] is giving you the whole column as an array, not a single value. You need to iterate over the values in the column, not try to convert the whole column array to integer value, with "%d" % df['column_name']. The Exception is giving you a good hint of what's wrong. It's probably saying "Type error: a number is required, not pandas.Dataframe" or something like that. More on reddit.com
🌐 r/learnpython
5
6
November 29, 2016
python - Formatting thousand separator for integers in a pandas dataframe - Stack Overflow
I'm assuming what you're actually asking for is how you can override the format for all integers: modify (i.e. "monkey patch") the IntArrayFormatter to print integer values with thousands separated by comma as follows: import pandas class _IntArrayFormatter(pandas.io.formats.format.Generic... More on stackoverflow.com
🌐 stackoverflow.com
python - Can you format pandas integers for display, like `pd.options.display.float_format` for floats? - Stack Overflow
I've seen this and this on formatting ... in pandas, but I'm interested in doing the same thing for integers. ... That works on the floats in my data, but will either leave annoying trailing zeroes on integers that are cast to floats, or I'll have plain integers that don't get formatted with commas... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Saturn Cloud
saturncloud.io › blog › how-to-format-thousand-separator-for-integers-in-a-pandas-dataframe
How to Format Thousand Separator for Integers in a Pandas DataFrame | Saturn Cloud Blog
December 6, 2023 - To format thousand separators for integers in a pandas DataFrame, we can define a function that takes a number as input and returns a string representation of the number with thousand separators. def format_int_with_commas(x): """ Formats an ...
🌐
DataScience Made Simple
datasciencemadesimple.com › home › format integer column of dataframe in python pandas
Format integer column of Dataframe in Python pandas - DataScience Made Simple
February 5, 2023 - # round to two decimal places in python pandas pd.options.display.float_format = '{:.2f}'.format print df · # Format with commas and round off to two decimal places in pandas pd.options.display.float_format = '{:,.2f}'.format print df
🌐
IncludeHelp
includehelp.com › python › format-a-number-with-commas-to-separate-thousands-in-pandas.aspx
Python - Format a number with commas to separate thousands in pandas
To format a number with commas to separate thousands, you can use pd.options.display method which contains a feature called float_format which will allow us to format these numbers in such a way that they can be separated with commas. ... # Importing pandas package import pandas as pd # Creating ...
🌐
DataScientYst
datascientyst.com › how-to-format-numbers-with-commas-for-thousands-in-pandas
How to Format Numbers with Commas for Thousands in Pandas
April 8, 2025 - To display large numbers in a more readable format we can insert commas as thousands separators in Pandas. This is especially useful when preparing data for presentation or reports. Below is a quick solution to format numbers with commas using Pandas: (1) Display Only df.style.format('{:,}') or
Find elsewhere
🌐
Pandas
pandas.pydata.org › docs › dev › reference › api › pandas.io.formats.style.Styler.format.html
pandas.io.formats.style.Styler.format — pandas documentation
Floating point precision to use for display purposes, if not determined by the specified formatter. ... Character used as decimal separator for floats, complex and integers. ... Character used as thousands separator for floats, complex and integers. ... Use ‘html’ to replace the characters &, <, >, ', and " in cell display string with HTML-safe sequences.
🌐
GeeksforGeeks
geeksforgeeks.org › formatting-integer-column-of-dataframe-in-pandas
Formatting float column of Dataframe in Pandas - GeeksforGeeks
January 10, 2024 - In this example below code uses pandas to create a DataFrame, 'products_dataframe,' with product names and their respective prices. It prints the initial DataFrame and then formats the 'Price' column with commas and rounds the values to two decimal places.
Top answer
1 of 4
15

pandas (as of 0.20.1) does not allow overriding the default integer format in an easy way. It is hard coded in pandas.io.formats.format.IntArrayFormatter (the lambda function):

class IntArrayFormatter(GenericArrayFormatter):

    def _format_strings(self):
        formatter = self.formatter or (lambda x: '% d' % x)
        fmt_values = [formatter(x) for x in self.values]
        return fmt_values

I'm assuming what you're actually asking for is how you can override the format for all integers: modify (i.e. "monkey patch") the IntArrayFormatter to print integer values with thousands separated by comma as follows:

import pandas

class _IntArrayFormatter(pandas.io.formats.format.GenericArrayFormatter):

    def _format_strings(self):
        formatter = self.formatter or (lambda x: ' {:,}'.format(x))
        fmt_values = [formatter(x) for x in self.values]
        return fmt_values

pandas.io.formats.format.IntArrayFormatter = _IntArrayFormatter

Note:

  • before 0.20.0, the formatters were in pandas.formats.format.
  • before 0.18.1, the formatters were in pandas.core.format.

Aside

For floats you do not need to jump through those hoops since there is a configuration option for it:

display.float_format: The callable should accept a floating point number and return a string with the desired format of the number. This is used in some places like SeriesFormatter. See core.format.EngFormatter for an example.

2 of 4
8

The formatters parameter in to_html will take a dictionary of column names mapped to a formatting function. Below has an example of a function to build a dict that maps the same function to both floats and ints.

In [250]: num_format = lambda x: '{:,}'.format(x)

In [246]: def build_formatters(df, format):
     ...:     return {column:format 
     ...:               for (column, dtype) in df.dtypes.iteritems()
     ...:               if dtype in [np.dtype('int64'), np.dtype('float64')]}
     ...: 

In [247]: formatters = build_formatters(df_int, num_format)


In [249]: print df_int.to_html(formatters=formatters)
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>A</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>20,000</td>
    </tr>
    <tr>
      <th>1</th>
      <td>10,000</td>
    </tr>
  </tbody>
</table>
🌐
Towards Data Science
towardsdatascience.com › home › latest › apply thousand separator (and other formatting) to pandas dataframe
Apply Thousand Separator (and Other Formatting) to Pandas Dataframe | Towards Data Science
January 28, 2025 - We’ll use the example shown above to illustrate how to make these format changes in a Pandas dataframe. The sample data used in this tutorial can be downloaded from [Redfin](http://redfin’s data center)’s open data center. Below is a quick overview of the sample data: ... Let’s start with the ‘Median Sales Price’ column and see how we can format it by adding the thousand comma separators and a dollar sign in the front.
Top answer
1 of 4
23

You could monkey-patch pandas.io.formats.format.IntArrayFormatter:

import contextlib
import numpy as np
import pandas as pd
import pandas.io.formats.format as pf
np.random.seed(2015)

@contextlib.contextmanager
def custom_formatting():
    orig_float_format = pd.options.display.float_format
    orig_int_format = pf.IntArrayFormatter

    pd.options.display.float_format = '{:0,.2f}'.format
    class IntArrayFormatter(pf.GenericArrayFormatter):
        def _format_strings(self):
            formatter = self.formatter or '{:,d}'.format
            fmt_values = [formatter(x) for x in self.values]
            return fmt_values
    pf.IntArrayFormatter = IntArrayFormatter
    yield
    pd.options.display.float_format = orig_float_format
    pf.IntArrayFormatter = orig_int_format


df = pd.DataFrame(np.random.randint(10000, size=(5,3)), columns=list('ABC'))
df['D'] = np.random.random(df.shape[0])*10000

with custom_formatting():
    print(df)

yields

      A     B     C        D
0 2,658 2,828 4,540 8,961.77
1 9,506 2,734 9,805 2,221.86
2 3,765 4,152 4,583 2,011.82
3 5,244 5,395 7,485 8,656.08
4 9,107 6,033 5,998 2,942.53

while outside of the with-statement:

print(df)

yields

      A     B     C            D
0  2658  2828  4540  8961.765260
1  9506  2734  9805  2221.864779
2  3765  4152  4583  2011.823701
3  5244  5395  7485  8656.075610
4  9107  6033  5998  2942.530551
2 of 4
12

Another option for Jupyter notebooks is to use df.style.format('{:,}'), but it only works on a single dataframe as far as I know, so you would have to call this every time:

table.style.format('{:,}')
          col1       col2
0s   9,246,452  6,669,310
>0   2,513,002  5,090,144

table
       col1     col2
0s  9246452  6669310
>0  2513002  5090144

Styling — pandas 1.1.2 documentation

🌐
Reddit
reddit.com › r/learnpython › pandas df: how to add thousand separators to a column?
r/learnpython on Reddit: Pandas df: How to add thousand separators to a column?
May 29, 2021 -

Two points here. I've 'pd.read_csv'ed a CSV file which has three columns.

I've used the following in order to extract the data and add headings to the columns (as currently the data is just naked)

Column 1 & 3 are text, and column 2 is a number.

How can I output the number with separators? EG 1,000,000 rather than 1000000

Also, what's the best way for formatting this dataframe to be included in an email body?

🌐
Practical Business Python
pbpython.com › styling-pandas.html
Stylin’ with Pandas - Practical Business Python
Using the format function, we can use all the power of python’s string formatting tools on the data. In this case, we use ${0:,.2f} to place a leading dollar sign, add commas and round the result to 2 decimal places.
🌐
Saturn Cloud
saturncloud.io › blog › how-to-format-numbers-in-a-python-pandas-dataframe-as-currency-in-thousands-or-millions
How to Format Numbers in a Python Pandas DataFrame as Currency in Thousands or Millions | Saturn Cloud Blog
January 6, 2024 - In this case, we will use the format string "{:,.0f}K", which formats the value as a comma-separated integer with no decimal places, followed by the letter “K” to indicate thousands. import pandas as pd # create a sample DataFrame with numerical ...