> ## Content Index
> Fetch the complete content index at: https://datascientyst.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to Format Numbers with Commas for Thousands in Pandas
- URL: https://datascientyst.com/how-to-format-numbers-with-commas-for-thousands-in-pandas/
- Published: 2025-04-08T20:31:15.000Z
- Updated: 2025-04-08T20:53:23.000Z
- Author: John D K
- Tags: Styling

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**

```python
df.style.format('{:,}')

```

or

```python
df.head().style.format("{:,.0f}")

```

**(2) Format parameter for thousands char**

```python
df.style.format(thousands=",")

```

**(3) Format multiple columns**

```python
col_format = {"sales": "{:,.0f}", "col2": "{:,.0f}"}
df.head().style.format(col_format)

```

**(4) pandas format comma thousands**

```python
df['sales'].apply(lambda x: f"{x:,}")

```

## Data

Suppose we have the following DataFrame:

```python
import pandas as pd

df = pd.DataFrame({
    'sales': [1000, 15000, 2500000]
})

df

```

data:

|   | sales   |
| - | ------- |
| 0 | 1000    |
| 1 | 15000   |
| 2 | 2500000 |

## Display Commas Without Changing Values

If you only need the formatted output for display purposes:

```python
df.style.format("{:,.0f}")

```

result:

|   | sales     |
| - | --------- |
| 0 | 1,000     |
| 1 | 15,000    |
| 2 | 2,500,000 |

## Multiple Columns with Custom Format

To apply this to multiple numeric columns:

```python
col_format = {"sales": "{:,.0f}", "col2": "{:,.0f}"}
df.head().style.format(col_format)

```

result:

|   | sales     |
| - | --------- |
| 0 | 1,000     |
| 1 | 15,000    |
| 2 | 2,500,000 |

## Format Column with Commas - New Column

Use `.apply` with Python’s built-in `format` function to create a new column or update existing one:

```python
import pandas as pd

df = pd.DataFrame({
    'sales': [1000, 15000, 2500000]
})

df['sales_nice'] = df['sales'].apply(lambda x: f"{x:,}")

```

**Output:**

|   | sales   | sales\_nice |
| - | ------- | ----------- |
| 0 | 1000    | 1,000       |
| 1 | 15000   | 15,000      |
| 2 | 2500000 | 2,500,000   |

## Resources

- [pandas.io.formats.style.Styler.format](https://pandas.pydata.org/docs/reference/api/pandas.io.formats.style.Styler.format.html?ref=datascientyst.com)
- [Convert string, K and M to number, Thousand and Million in Pandas/Python](https://datascientyst.com/convert-string-k-m-to-number-thousand-million-pandas-python/)
- [Format a number with commas to separate thousands](https://stackoverflow.com/questions/43102734/format-a-number-with-commas-to-separate-thousands?ref=datascientyst.com)