Try this example:

df = pd.DataFrame({
        'date':['1/15/2016','2/1/2016','2/15/2016','3/15/2016'],
        'numA':[1000,2000,3000,4000.3],
        'numB':[10000,20000.2,30000,40000]
    })

writer = pd.ExcelWriter('c:/.../pandas_excel_test.xlsx', engine = 'xlsxwriter')
df.to_excel(writer, index=False, sheet_name='Sheet1')
workbook  = writer.book
worksheet = writer.sheets['Sheet1']
format1 = workbook.add_format({'num_format': '0.00'})
worksheet.set_column('C:C', None, format1)  # Adds formatting to column C
writer.save()

You can change the format 0.00 in the .add_format({'num_format': '0.00'}) on your desired format, for example, 0.0000 for four decimal places. Note this only applies to column C.

If you want to change the formatting of all columns, modify the worksheet.set_column('C:C', None, format1), for example

worksheet.set_column(0, 3, None, format1) 

where 0 the first column and 3 the final column.

Check more formatting here: https://xlsxwriter.readthedocs.io/worksheet.html

Answer from Eddy Piedad on Stack Overflow
๐ŸŒ
Python Forum
python-forum.io โ€บ thread-33558.html
[Pandas] Write data to Excel with dot decimals - Python Forum
May 5, 2021 - Hello everyone, I looked everywhere but I can't seem to find a solution to my problem. I have a text file containing data with decimal type '.'. Using read_csv, I import the data to python. The problem is that when I want to write it to Excel my dat...
Discussions

python - Read excel data into pandas dataframe to 20 decimal places - Stack Overflow
I am trying to read data from excel using pandas.ExcelFile() into a dataframe, and then outputting a text file using to_csv. This output text file should be at precision of 20 decimal places and More on stackoverflow.com
๐ŸŒ stackoverflow.com
October 31, 2018
python - Setting default number format when writing to Excel from Pandas - Stack Overflow
Should this code be executed after ... df.to_excel(), changing number_format and then saving the workbook? 2023-09-22T21:03:30.797Z+00:00 ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... Iโ€™m Jody, the Chief Product and Technology Officer at Stack Overflow. Letโ€™s... ... New site design and philosophy for Stack Overflow: Starting February 24, 2026... 1 Display 2 decimal places, and use comma as separator in pandas... More on stackoverflow.com
๐ŸŒ stackoverflow.com
BUG: Dataframe.to_excel treats decimal.Decimal as string instead of numeric type, the data in the Excel cell is formatted as a string, not a number
Pandas version checks I have checked that this issue has not already been reported. I have confirmed this bug exists on the latest version of pandas. I have confirmed this bug exists on the main br... More on github.com
๐ŸŒ github.com
6
November 9, 2022
Dataframe.to_excel treats decimal.Decimal as string instead of numeric type, the data in the Excel cell is formatted as a string, not a number
Code Sample (float output is prepared for the sake of comparison to Decimal) # ---------------------------------- ### imports import pandas as pd import decimal as dc # ---------------------------------- ### definitions value_str = '2.44... More on github.com
๐ŸŒ github.com
2
May 3, 2019
๐ŸŒ
GitHub
github.com โ€บ pandas-dev โ€บ pandas โ€บ issues โ€บ 14403
Add decimal option to read_excel ยท Issue #14403 ยท pandas-dev/pandas
October 12, 2016 - The pd.read_csv() function has a decimal option, which allows it to parse European dates very easily: pd.read_csv("afile.csv", decimal=',') This option is not present in pd.read_excel(), but it could also be very useful there. It would b...
Author ย  bbirand
Top answer
1 of 2
14

I got this format the floats to 1 decimal place.

data = {'A Prime': {0: 3.26,  1: 3.24,  2: 3.22,  3: 3.2,  4: 3.18,  5: 3.16,
  6: 3.14,  7: 1.52,  8: 1.5,  9: 1.48,  10: 1.46,  11: 1.44,  12: 1.42},
 'B': {0: 0.16608,  1: 0.16575,  2: 0.1654,  3: 0.16505999999999998,  4: 0.1647,  5: 0.16434,  6: 0.16398,  7: 0.10759,  8: 0.10687,  9: 0.10614000000000001,
  10: 0.10540999999999999,  11: 0.10469,  12: 0.10396}, 'Proto Name': {0: 'Alpha',
  1: 'Alpha',  2: 'Alpha', 3: 'Alpha',  4: 'Alpha',  5: 'Alpha',  6: 'Alpha',  7: 'Bravo',  8: 'Bravo',  9: 'Bravo',  10: 'Bravo',  11: 'Bravo',  12: 'Bravo'}}

import pandas as pd
df = pd.DataFrame(data)


    A Prime B       Proto Name
0   3.26    0.16608 Alpha
1   3.24    0.16575 Alpha
2   3.22    0.16540 Alpha
3   3.20    0.16506 Alpha
4   3.18    0.16470 Alpha
5   3.16    0.16434 Alpha
6   3.14    0.16398 Alpha
7   1.52    0.10759 Bravo
8   1.50    0.10687 Bravo
9   1.48    0.10614 Bravo
10  1.46    0.10541 Bravo
11  1.44    0.10469 Bravo
12  1.42    0.10396 Bravo

writer = pd.ExcelWriter(r'c:\temp\output.xlsx')
# This method will truncate the data past the first decimal point
df.to_excel(writer,'Sheet1',float_format = "%0.1f")
writer.save()

but that alas is not perhaps all cases - no joy with say larger numbers and thousands separator

df.to_excel(writer,'Sheet1',float_format = ":,")

However the following seems to work

data = {'A Prime': {0: 326000,  1: 3240000}}
df = pd.DataFrame(data)

    A Prime
0   326000
1   3240000

writer = pd.ExcelWriter(r'c:\temp\output.xlsx')
df.to_excel(writer,'Sheet1')
workbook  = writer.book
worksheet = writer.sheets['Sheet1']
format1 = workbook.add_format({'num_format': '#,##0.00'})
worksheet.set_column('B:B', 18, format1)
#Alternatively, you could specify a range of columns with 'B:D' and 18 sets the column width
writer.close()

All taken from here: http://xlsxwriter.readthedocs.io/working_with_pandas.html

2 of 2
4

For what it's worth and because the question was also tagged for openpyxl, you can also also edit the default style of a whole workbook in openpyxl. This could make sense for the number format but can have unexpected consquences if things like the font size is changed, because other GUI elements are affected. The following should work, if used with caution.

wb._named_styles['Normal'].number_format = '#,##0.00'
๐ŸŒ
GitHub
github.com โ€บ pandas-dev โ€บ pandas โ€บ issues โ€บ 49598
BUG: Dataframe.to_excel treats decimal.Decimal as string instead of numeric type, the data in the Excel cell is formatted as a string, not a number ยท Issue #49598 ยท pandas-dev/pandas
November 9, 2022 - Values in both dataframes should be written to excel as number. ... commit : 91111fd python : 3.9.13.final.0 python-bits : 64 OS : Linux OS-release : 6.0.5-200.fc36.x86_64 Version : #1 SMP PREEMPT_DYNAMIC Wed Oct 26 15:55:21 UTC 2022 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_GB.UTF-8 LOCALE : en_GB.UTF-8 ยท pandas : 1.5.1 numpy : 1.23.4 pytz : 2022.6 dateutil : 2.8.2 setuptools : 65.5.1 pip : 22.3.1 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psyco
Author ย  rspocz
๐ŸŒ
GitHub
github.com โ€บ pandas-dev โ€บ pandas โ€บ issues โ€บ 26277
Dataframe.to_excel treats decimal.Decimal as string instead of numeric type, the data in the Excel cell is formatted as a string, not a number ยท Issue #26277 ยท pandas-dev/pandas
May 3, 2019 - Dataframe.to_excel treats decimal.Decimal as string instead of numeric type, the data in the Excel cell is formatted as a string, not a number#26277 ... BugIO Excelread_excel, to_excelread_excel, to_excelNumeric OperationsArithmetic, Comparison, and Logical operationsArithmetic, Comparison, and Logical operations ... # ---------------------------------- ### imports import pandas as pd import decimal as dc # ---------------------------------- ### definitions value_str = '2.445' # ---------------------------------- ### instantiations #df_float = pd.DataFrame(data=[float(value_str)]) df_decimal = pd.DataFrame(data=[dc.Decimal(value_str)]) # ---------------------------------- ### exports # excel #df_float.to_excel('float' + '.xlsx') df_decimal.to_excel('decimal' + '.xlsx')
Author ย  3f0c4
๐ŸŒ
Medium
medium.com โ€บ @tubelwj โ€บ how-to-set-decimal-precision-and-display-formats-in-pandas-abf95de04b53
How to Set Data Decimal Precision and Display Formats in Pandas | by Gen. Devin DL. | Medium
December 14, 2025 - However, due to the limited precision of floating-point representation, precision loss and rounding errors may occur. If we want to specify decimal precision, there are several methods: a) Using the round() method to set the number of decimal places.
Find elsewhere
๐ŸŒ
Pandas
pandas.pydata.org โ€บ docs โ€บ reference โ€บ api โ€บ pandas.io.formats.style.Styler.format.html
pandas.io.formats.style.Styler.format โ€” pandas 3.0.2 documentation
When instantiating a Styler, default formatting can be applied by setting the pandas.options: ... Styler.format is ignored when using the output format Styler.to_excel, since Excel and Python have inherently different formatting structures. However, it is possible to use the number-format pseudo ...
๐ŸŒ
XlsxWriter
xlsxwriter.readthedocs.io โ€บ example_pandas_column_formats.html
Example: Pandas Excel output with column formatting โ€” XlsxWriter
writer = pd.ExcelWriter("pandas_column_formats.xlsx", engine="xlsxwriter") # Convert the dataframe to an XlsxWriter Excel object. df.to_excel(writer, sheet_name="Sheet1") # Get the xlsxwriter workbook and worksheet objects. workbook = writer.book worksheet = writer.sheets["Sheet1"] # Add some cell formats.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ formatting-integer-column-of-dataframe-in-pandas
Formatting float column of Dataframe in Pandas - GeeksforGeeks
October 3, 2025 - This article covers simple ways to format floats in Pandas. You can round float values to a fixed number of decimal places using pd.options.display.float_format.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ dealing with excel files using mixed thousands and decimal separators
r/learnpython on Reddit: Dealing with excel files using mixed thousands and decimal separators
December 1, 2016 -

I have a few excel files that I want to process but they use a mix of thousands and decimal separators.

For example, 1.000.000 and 50,56 on one file and 1,000,000 and 50.56 on another.

This is the function that I use:

import os
import pandas

def process_file(data_file):
	try:
		df = pd.read_excel(data_file, header=None, na_values=["", "-", " "], 
						   thousands=".", decimal=",")
		print "XLS"
	except Exception as e:
		df = pd.read_html(data_file, header=None, na_values=["", "-", " "],
						  thousands=".", decimal=",")
		df = df[0]
		print "HTML"
				  
	df = df.iloc[3:] #, :8] # Remove header rows
	df.reset_index(drop=True, inplace=True) # Because we removed top rows

	column_names = ["N", "DATE", "J1", "J2", "J3", "J4", "J5", "J6", "T",
					"S5+1", "P5+1", "S5", "P5", "S4+1", "P4+1",
					"S4", "P4", "S3+1", "P3+1", "S3", "P3",
					"S2+1", "P2+1", "S1+1", "P1+1"]
	df.columns = column_names

	numeric_colums = ["N", "J1", "J2", "J3", "J4", "J5", "J6", "T",
					  "S5+1", "P5+1", "S5", "P5", "S4+1", "P4+1",
					  "S4", "P4", "S3+1", "P3+1", "S3", "P3",
					   "S2+1", "P2+1", "S1+1", "P1+1"]
	df.replace(u"Not available", 0, inplace=True)
	df.replace(np.nan, 0, inplace=True)
	
	# Convert coulmns with numbers
	for num_col in numeric_colums:
		try:
			df[num_col] = df[num_col].astype(float)
		except Exception as e:
			print e
			
	df.DATE = pd.to_datetime(df.DATE)
	df.sort_values(by="N", inplace=True)
	
	return df

When the thousands and decimal are wrong I get an error if I try to convert the columns into numbers.

Is there a way to find out which combination of separators is used in each file ?

๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ anyone else please ***pandas formatting***
r/learnpython on Reddit: Anyone else please ***Pandas Formatting***
July 22, 2021 -

Hi - how to convert decimal numbers such as 0.0555 to percent to display percentage sign as 5.55% ?

I tried below I have two problems:

  1. some values have 1 and some two decimals in my output excel file.

  2. when I export to excel it's string not value. When I convert to value manually in excel I get two see two decimal places.

How to solve this in pandas, to display two decimal places with percent sign and to be value. Keep in mind that excel file will feed client database and can't be text or string.

df["Value"]= df["Value"].astype(float)

df["Value"]=df["Value"]*100

df["Value"]=df["Value"].round(2)

df["Value"]=df["Value"].astype(str) + "%"

๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ rounding when using pandas to read in excel data
r/learnpython on Reddit: Rounding when using Pandas to read in Excel data
June 16, 2021 -

I have an .xlsx file that I am reading in using pd.read_excel.

The format of entire Excel sheet seems to be 'General', and contains text and numbers.

When I read the data in, and extract the number data, the numbers seem to be rounded, so a number like 64.119, will appear in the DataFrame as 64.12. Is there any way to ensure I get the correct number (i.e. 64.119)?

Thanks.

๐ŸŒ
Pandas
pandas.pydata.org โ€บ docs โ€บ reference โ€บ api โ€บ pandas.read_excel.html
pandas.read_excel โ€” pandas 3.0.2 documentation - PyData |
Thousands separator for parsing string columns to numeric. Note that this parameter is only necessary for columns stored as TEXT in Excel, any numeric columns will automatically be parsed, regardless of display format. ... Character to recognize as decimal point for parsing string columns to ...
๐ŸŒ
Data to Fish
datatofish.com โ€บ round-values-pandas-dataframe
How to Round Values in a pandas DataFrame
import pandas as pd data = {'fish': ['salmon', 'pufferfish', 'shark'], 'length_m': [1.523, 0.2165, 2.1], 'width_cm': [10.2, 3.14159, 90.0] } df = pd.DataFrame(data) print(df) fish length_m width_cm 0 salmon 1.5230 10.20000 1 pufferfish 0.2165 3.14159 2 shark 2.1000 90.00000 ยท To round the the length_m column to two decimals places, run the following:
๐ŸŒ
Trymito
trymito.io โ€บ excel-to-python โ€บ functions โ€บ math โ€บ ROUND
Excel to Python: ROUND Function - A Complete Guide | Mito
Similar to how =ROUND(A1, 2) rounds the value in cell A1 to 2 decimal places in Excel, in pandas, you use the `round` function.