To get the separator you can do: df['col'] = df['col'].apply(lambda x : "{:,}".format(x)) Beware that this converts your integers/floats to strings. To include a Dataframe in an email body, I think converting the df to an html table would make sense. See pandas' .to_html() method. Answer from sarrysyst on reddit.com
🌐
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?

Discussions

python - How to add thousand separator to numbers in pandas - Stack Overflow
Assuming that I have a pandas dataframe and I want to add thousand separators to all the numbers (integer and float), what is an easy and quick way to do it? More on stackoverflow.com
🌐 stackoverflow.com
excel - How to insert a comma as a thousands separator in a pandas dataframe column? - Stack Overflow
I'm trying to format the Dollar Amount column to have a comma thousands separator for easier viewing, but I haven't been able to figure it out. Can someone please show me the way? import pandas as... More on stackoverflow.com
🌐 stackoverflow.com
python - Formatting thousand separator for integers in a pandas dataframe - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
Thousands Separator in a Number Column of Data Editor
Summary How to show thousands separator in a Number Column inside the Data Editor component introduced in streamlit 1.23? I tried to set the number format to “%,.2f” as it is recognized by the defautl pandas DataFrame Styler, but this format results in erro when used in the Data Editor. More on discuss.streamlit.io
🌐 discuss.streamlit.io
0
0
June 14, 2023
🌐
Pandas
pandas.pydata.org › docs › user_guide › reshaping.html
Reshaping and pivot tables — pandas 3.0.1 documentation
As with the Series version, you can pass values for the prefix and prefix_sep. By default the column name is used as the prefix and _ as the prefix separator.
🌐
Real Python
realpython.com › how-to-pandas-pivot-table
How to Create Pivot Tables With pandas – Real Python
May 24, 2024 - For this example, you can ignore the overall total rows and columns, but you should apply a currency format using the $ symbol and use the underscore (_) character as your thousands separator.
🌐
pandas
pandas.pydata.org › pandas-docs › dev › reference › api › pandas.io.formats.style.Styler.format.html
pandas.io.formats.style.Styler.format — pandas 3.0.0.dev0+2000.gf1b00b8e37 documentation
Styler.format(formatter=None, subset=None, na_rep=None, precision=None, decimal='.', thousands=None, escape=None, hyperlinks=None)[source]#
🌐
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 - 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:
Find elsewhere
🌐
Pandas
pandas.pydata.org › pandas-docs › stable › user_guide › reshaping.html
Reshaping and pivot tables — pandas 2.3.3 documentation
As with the Series version, you can pass values for the prefix and prefix_sep. By default the column name is used as the prefix and _ as the prefix separator.
🌐
Python Forum
python-forum.io › Thread-thousands-separator-format-on-df-column
thousands separator format on df column
March 2, 2017 - Dear Python Experts, I an trying to convert my PopEst column so a thousands separator gets added. def thirteen(): Top15 = answer_one() Top15['PopEst'] = Top15['Energy Supply'] / Top15['Energy Supply per Capita'] PopEst = To...
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>
🌐
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 - We are using map() instead · 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.
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 1.4 › user_guide › reshaping.html
Reshaping and pivot tables — pandas 1.4.4 documentation
While pivot() provides general purpose pivoting with various data types (strings, numerics, etc.), pandas also provides pivot_table() for pivoting with aggregation of numeric data.
🌐
Pandas
pandas.pydata.org › docs › dev › reference › api › pandas.io.formats.style.Styler.format.html
pandas.io.formats.style.Styler.format — pandas documentation
Styler.format(formatter=None, subset=None, na_rep=None, precision=None, decimal='.', thousands=None, escape=None, hyperlinks=None)[source]#
🌐
Medium
medium.com › data-science › apply-thousand-separator-and-other-formatting-to-pandas-dataframe-45f2f4c7ab01
Apply Thousand Separator (and Other Formatting) to Pandas Dataframe | by Analyst Sharone | TDS Archive | Medium
January 18, 2023 - If we were going to visualize this data in a graph, would you prefer to show the information in the tooltip from the top or the bottom table? Press enter or click to view image in full size · Image by Author · In this post, I’ll share with you a couple of pandas formatting tricks that deal with these common formatting problems: Insert thousand comma separators to numbers ·
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 1.5 › user_guide › reshaping.html
Reshaping and pivot tables — pandas 1.5.2 documentation
While pivot() provides general purpose pivoting with various data types (strings, numerics, etc.), pandas also provides pivot_table() for pivoting with aggregation of numeric data.
🌐
Streamlit
discuss.streamlit.io › using streamlit
Thousands Separator in a Number Column of Data Editor - Using Streamlit - Streamlit
June 14, 2023 - Summary How to show thousands separator in a Number Column inside the Data Editor component introduced in streamlit 1.23? I tried to set the number format to “%,.2f” as it is recognized by the defautl pandas DataFrame S…
🌐
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.