The accepted answer suggests to modify the raw data for presentation purposes, something you generally do not want. Imagine you need to make further analyses with these columns and you need the precision you lost with rounding.

You can modify the formatting of individual columns in data frames, in your case:

output = df.to_string(formatters={
    'var1': '{:,.2f}'.format,
    'var2': '{:,.2f}'.format,
    'var3': '{:,.2%}'.format
})
print(output)

For your information '{:,.2%}'.format(0.214) yields 21.40%, so no need for multiplying by 100.

You don't have a nice HTML table anymore but a text representation. If you need to stay with HTML use the to_html function instead.

from IPython.core.display import display, HTML
output = df.to_html(formatters={
    'var1': '{:,.2f}'.format,
    'var2': '{:,.2f}'.format,
    'var3': '{:,.2%}'.format
})
display(HTML(output))

Update

As of pandas 0.17.1, life got easier and we can get a beautiful html table right away:

df.style.format({
    'var1': '{:,.2f}'.format,
    'var2': '{:,.2f}'.format,
    'var3': '{:,.2%}'.format,
})
Answer from linqu on Stack Overflow
๐ŸŒ
Saturn Cloud
saturncloud.io โ€บ blog โ€บ how-to-format-certain-floating-dataframe-columns-into-percentage-in-pandas
How to Format Certain Floating Dataframe Columns into Percentage in Pandas | Saturn Cloud Blog
December 19, 2023 - To format a floating dataframe column into a percentage in Pandas, you can use the map and format methods. Letโ€™s start by setting up a scenario with a sample DataFrame: import pandas as pd # Creating a sample DataFrame data = { 'Product': ...
Discussions

python - pandas convert columns to percentages of the totals - Stack Overflow
Divide the dataframe by the resulting ... the columns. To finish, multiply the results by 100 so they are percentages between 0 and 100 instead of proportions between 0 and 1 (or you can skip this step and store them as proportions). ... Thank you so much this did the trick. Thanks for explaining the portions as well. Pandas seems to be ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
pandas - format number (based on calculation) as a percentage to two decimal places using python - Stack Overflow
If I do as you suggested it returns a string, I want it to be a number (I want to use it for calculations). 2014-03-13T04:27:20.907Z+00:00 ... @yoshiserry: If you want a number, keep percent_val. format_percent is a string. Do the math with numbers, and convert to strings for display purposes. 2014-03-13T04:28:54.437Z+00:00 ... how do I do that if I want to do this with columns in a pandas dataframe? I have the budget, actual, and percentage ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Formatting floating point values as percent in column_config
Summary How do I transform a floating point value as a percentage in column_config? lambda x: f'{x:.2f}%' Code Snipet df = pd.DataFrame( [ dict(amount=100, percent=0.04), dict(amount=120, percent=0.05), dict(amount=360, percent=0.03), ] ) edited_df = st.data_editor( data=df, column_config=dict( ... More on discuss.streamlit.io
๐ŸŒ discuss.streamlit.io
0
0
June 25, 2023
Converting pandas column to percentage

Showing us what CSV_DAX['EL4F'] and date_DAX looks like would help us a lot. What you have seems okay with the limited information you gave us.

More on reddit.com
๐ŸŒ r/learnpython
6
0
April 9, 2015
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ format to percent in pandas ***help***
r/learnpython on Reddit: Format to Percent in Pandas ***HELP***
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) + "%"

๐ŸŒ
XlsxWriter
xlsxwriter.readthedocs.io โ€บ example_pandas_percentage.html
Example: Pandas Excel output with percentage formatting โ€” XlsxWriter
# # SPDX-License-Identifier: BSD-2-Clause # # Copyright (c) 2013-2025, John McNamara, jmcnamara@cpan.org # import pandas as pd # Create a Pandas dataframe from some data. df = pd.DataFrame({"Names": ["Anna", "Arek", "Arun"], "Grade": ["100%", "70%", "85%"]}) # Convert the percentage strings to percentage numbers. df["Grade"] = df["Grade"].str.replace("%", "") df["Grade"] = df["Grade"].astype(float) df["Grade"] = df["Grade"].div(100) # Create a Pandas Excel writer using XlsxWriter as the engine. writer = pd.ExcelWriter("pandas_percent.xlsx", engine="xlsxwriter") # Convert the dataframe to an Xl
๐ŸŒ
YouTube
youtube.com โ€บ how to fix your computer
PYTHON : Format certain floating dataframe columns into percentage in pandas - YouTube
PYTHON : Format certain floating dataframe columns into percentage in pandas [ Gift : Animated Search Engine : https://www.hows.tech/p/recommended.html ] PY...
Published ย  December 5, 2021
Views ย  473
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-calculate-the-percentage-of-a-column-in-pandas
How to Calculate the Percentage of a Column in Pandas - GeeksforGeeks
July 15, 2025 - Example 1: calculate the Percentage of a column in Pandas ... # Import required libraries import pandas as pd import numpy as np # Dictionary df1 = { 'Name': ['abc', 'bcd', 'cde', 'def', 'efg', 'fgh', 'ghi'], 'Math_score': [52, 87, 49, 74, 28, 59, 48]} # Create a DataFrame df1 = pd.DataFrame(df1, columns = ['Name', 'Math_score']) # Calculating Percentage df1['percent'] = (df1['Math_score'] / df1['Math_score'].sum()) * 100 # Show the dataframe df1
๐ŸŒ
Pandas
pandas.pydata.org โ€บ docs โ€บ reference โ€บ api โ€บ pandas.io.formats.style.Styler.format.html
pandas.io.formats.style.Styler.format โ€” pandas 3.0.1 documentation
If formatter is given as a string this is assumed to be a valid Python format specification and is wrapped to a callable as string.format(x). If a dict is given, keys should correspond to column names, and values should be string or callable, as above. The default formatter currently expresses floats and complex numbers with the pandas display precision unless using the precision argument here.
Find elsewhere
๐ŸŒ
Practical Business Python
pbpython.com โ€บ styling-pandas.html
Stylinโ€™ with Pandas - Practical Business Python
Percentages are another useful example where formatting the output makes it simpler to understand the underlying analysis. For instance, which is quicker to understand: .05 or 5%? Using the percentage sign makes it very clear how to interpret the data. The key item to keep in mind is that styling presents the data so a human can read it but keeps the data in the same pandas data type so you can perform your normal pandas math, date or string functions.
๐ŸŒ
Datasnips
datasnips.com โ€บ 164 โ€บ how-to-convert-dataframe-values-into-percentages
Python | How to Convert DataFrame Values Into Percentages | Datasnips
#PANDAS ยท #MATPLOTLIB ยท #SEABORN ... the row. First we create a 'total' column for each row and then use pipe and lambda to divide each value in the row by the 'total' column and format as a percentage....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ how-to-calculate-the-percentage-of-a-column-in-pandas
How to calculate the Percentage of a column in Pandas ? - GeeksforGeeks
September 29, 2023 - A Percentage is calculated by the mathematical formula of dividing the value by the sum of all the values and then multiplying the sum by 100. This is also applicable in Pandas Dataframes.
๐ŸŒ
Statology
statology.org โ€บ home โ€บ pandas: how to represent value_counts as percentage
Pandas: How to Represent value_counts as Percentage
December 1, 2022 - import pandas as pd #create DataFrame df = pd.DataFrame({'team': ['A', 'A', 'B', 'B', 'B', 'B', 'B', 'C'], 'points': [15, 12, 18, 20, 22, 28, 35, 40]}) #view DataFrame print(df) team points 0 A 15 1 A 12 2 B 18 3 B 20 4 B 22 5 B 28 6 B 35 7 C 40 ยท The following code shows how to count the occurrence of each value in the team column and represent the occurrences as a percentage of the total, formatted as a decimal:
๐ŸŒ
Stacked Turtles
kiwidamien.github.io โ€บ stylish-pandas.html
Stylish Pandas
November 6, 2019 - To set the number format for all ... format for a specific set of columns, use df.style.format(format_dict), where format_dict has column names as keys, and format strings as values....
๐ŸŒ
Streamlit
discuss.streamlit.io โ€บ using streamlit
Formatting floating point values as percent in column_config - Using Streamlit - Streamlit
June 25, 2023 - Summary How do I transform a floating ... amount=st.column_config.NumberColumn('Amount', format='$%.2f'), percent=st.column_config.NumberColumn('Percent', format='%.2f %%'), # TODO: ......
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ converting pandas column to percentage
r/learnpython on Reddit: Converting pandas column to percentage
April 9, 2015 -

Hey folks, I downloaded a CSV file from the internet and I wanted to convert one column into percentage with the first value in the column being 100 %. My approach looks as follows:

In the first step I fetch the first value of the column and make it a variable:

DAX_first=CSV_DAX['EL4F'].iloc[0]

In the second step I try to turn everything into percentages by the following:

plt.plot(date_DAX, CSV_DAX['EL4F']/DAX_first*100)

data_DAX contains the values for the X-axis obviously. The plot that I obtain doens't start at 100% but instead at around 60 %. Probably there's a blatant mistake somewhere but I don't see it at the moment. Can anyone spot the mistake?

Top answer
1 of 1
2

If you're only dealing with the one column (gross margins) or don't mind the same formatting being applied to all float values, the code below should work. If you need to format just a single column in your dataframe, you may need to convert the values to a string (making further calculations break, since you mentioned this is a requirement). An option for this latter case would be to simply make a copy of the dataframe, format that copy for display, but keep the original for calculations. I couldn't get the df.style.format() methods mentioned in similar questions to work, possibly due to Pandas version.

import pandas as pd
# pd version == 2.0.1

margin_data = {"margins":[0.3646, 0.2584, 0.8954]}
my_df = pd.DataFrame(margin_data)

# What you were printing before
print("Old formatting")
gross_margins = my_df['margins']
print(gross_margins)

# Apply new formatting to all floats
print("\nNew formatting")
pd.options.display.float_format = '{:.2%}'.format
gross_margins = my_df['margins']
print(gross_margins)

# Confirm values are still what you expect
print("\nValues")
print(my_df['margins'].iloc[0])

# Apply formatting to only one column, but makes 
# values a string instead of float
print("\nString formatting single column")
margin_data["more data"] = [1,2,3]
my_df2 = pd.DataFrame(margin_data)
my_df2['margins'].map('{:.2%}'.format)
print(my_df2)

Produces:

Old formatting
0    0.3646
1    0.2584
2    0.8954
Name: margins, dtype: float64

New formatting
0   36.46%
1   25.84%
2   89.54%
Name: margins, dtype: float64

Values
0.3646

String formatting single column
   margins  more data
0   36.46%          1
1   25.84%          2
2   89.54%          3
๐ŸŒ
Stringfest Analytics
stringfestanalytics.com โ€บ home โ€บ blog โ€บ how to format a column as percentage in excel using openpyxl
How to format a column as percentage in Excel using openpyxl - Stringfest Analytics
May 22, 2023 - Excelโ€™s popularity is attributed ... data formatting and presentation features. Although Python offers distinct advantages for Excel, its raw data output is often unsuitable for business purposes. The following notebook demonstrates how to create a calculated percentage column in pandas and format ...