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
๐ŸŒ
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) + "%"

Discussions

python - pandas convert columns to percentages of the totals - Stack Overflow
I have a dataframe with 4 columns an ID and three categories that results fell into 90 id 1 2 4 4 2 3 6 1 3 7 0 3 I would like to convert it to 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
pandas - format number (based on calculation) as a percentage to two decimal places using python - Stack Overflow
The values: budget = 11,000 actual = 10,000 variance = budget - actual (1,000) total, would be the value of budget variable: 11,000 My Code: percent_val = variance/total format_perce... More on stackoverflow.com
๐ŸŒ stackoverflow.com
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
March 9, 2017
๐ŸŒ
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 - The Discount column contains floating-point values that represent percentages. To format the Discount column as a percentage, we use the map method to apply a formatting string to each value in the column.
๐ŸŒ
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
๐ŸŒ
Pandas
pandas.pydata.org โ€บ docs โ€บ reference โ€บ api โ€บ pandas.DataFrame.pct_change.html
pandas.DataFrame.pct_change โ€” pandas 3.0.1 documentation
Despite the name of this method, ... change. If you need the percentage change, multiply these values by 100. ... Periods to shift for forming percent change. ... Must be None. This argument will be removed in a future version of pandas....
๐ŸŒ
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....
Find elsewhere
๐ŸŒ
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 - Cumulative Percentage is calculated by the mathematical formula of dividing the cumulative sum of the column by the mathematical sum of all the values and then multiplying the result by 100.
๐ŸŒ
Practical Business Python
pbpython.com โ€บ styling-pandas.html
Stylinโ€™ with Pandas - Practical Business Python
We know how to style our numbers but now we have a combination of dates, percentages and currency. Fortunately we can use a dictionary to define a unique formatting string for each column.
๐ŸŒ
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
๐ŸŒ
Stacked Turtles
kiwidamien.github.io โ€บ stylish-pandas.html
Stylish Pandas
November 6, 2019 - Let's make the percentages look nice. Here is an example of how to format percentages: ... To style the dataframe df, we can use the df.style.format(format_dict), where format_dict has column names for keys, and the format string as the value. We can called our dataframe contribution to contain ...
๐ŸŒ
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 ... data=df, column_config=dict( amount=st.column_config.NumberColumn('Amount', format='$%.2f'), percent=st.column_config.NumberColumn('Percent', format='%.2f %%'), # TODO: ....
๐ŸŒ
Statology
statology.org โ€บ home โ€บ pandas: how to represent value_counts as percentage
Pandas: How to Represent value_counts as Percentage
December 1, 2022 - You can use the value_counts() function in pandas to count the occurrences of values in a given column of a DataFrame. To represent the values as percentages, you can use one of the following methods: Method 1: Represent Value Counts as Percentages (Formatted as Decimals)
๐ŸŒ
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 - # Import required libraries import ... columns = ['Name', 'Math_score']) # Calculating Percentage df1['percent'] = (df1['Math_score'] / df1['Math_score'].sum()) * 100 # Show the dataframe df1...
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ converting pandas column to percentage
r/learnpython on Reddit: Converting pandas column to percentage
March 9, 2017 -

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 2
11

You could use .apply('{:.0%}'.format):

import pandas as pd

df = pd.DataFrame([(168,219,185,89,112), (85,85,84,41,46)], 
                  index=['Total Listings', 'Total Sales'], columns=list(range(1,6)))
df.loc['Total Sales Rate'] = ((df.loc['Total Sales']/df.loc['Total Listings'])
                              .apply('{:.0%}'.format))

print(df)

yields

                    1    2    3    4    5
Total Listings    168  219  185   89  112
Total Sales        85   85   84   41   46
Total Sales Rate  51%  39%  45%  46%  41%

Notice that the Python str.format method has a built-in % format which multiplies the number by 100 and displays in fixed ('f') format, followed by a percent sign.


It is important to be aware that Pandas DataFrame columns must have a single dtype. Changing one value to a string forces the entire column to change its dtype to the generic object dtype. Thus the int64s or int32s in the Total Listings and Total Sales rows get recast as plain Python ints. This prevents Pandas from taking advantage of fast NumPy-based numerical operations which only work on native NumPy dtypes (like int64 or float64 -- not object).

So while the above code achieves the desired look, it isn't advisable to use this if further computation is to be done on the DataFrame. Instead, only convert to strings at the end if you need to do so for presentation.

Or, alternatively, transpose your DataFrame so the Total Sales Rate strings are in a column, not a row:

import pandas as pd

df = pd.DataFrame([(168,219,185,89,112), (85,85,84,41,46)], 
                  index=['Total Listings', 'Total Sales'], columns=list(range(1,6))).T

df['Total Sales Rate'] = ((df['Total Sales']/df['Total Listings'])
                              .apply('{:.0%}'.format))

print(df)

yields

   Total Listings  Total Sales Total Sales Rate
1             168           85              51%
2             219           85              39%
3             185           84              45%
4              89           41              46%
5             112           46              41%

The reason why

block_combine.loc["Total Sales Rate"] = pd.Series(["{0:.0f}%".format(val * 100) for val in block_combine.loc["Total Sales Rate"]])

shifted the values to the left by one column is because the new Series has an index which starts at 0 not 1. Pandas aligns the index of the Series on the right with the index of block_combine.loc["Total Sales Rate"] before assigning values to block_combine.loc["Total Sales Rate"].

Thus, you could alternatively have used:

block_combine.loc["Total Sales Rate"] = pd.Series(["{0:.0f}%".format(val * 100) 
    for val in block_combine.loc["Total Sales Rate"]], 
    index=block_combine.columns)
2 of 2
0
df = pd.DataFrame({
        1: [168,85], 
        2: [219,85],  
        3: [185,84],  
        4: [89,41], 
        5: [112,46]
    }, index=['Total Listings', 'Total Sales'])

total_sales_rate = pd.Series(df.loc['Total Sales'] / df.loc['Total Listings'] * 100, name='Total Sales Rate').round()
df = df.append(total_sales_rate)

Result...

                    1    2    3   4    5
Total Listings    168  219  185  89  112
Total Sales        85   85   84  41   46
Total Sales Rate   51   39   45  46   41