Use

>>> df.iloc[:, 1:] = df.iloc[:, 1:].div(df['total'], axis=0).mul(100).round(2).astype(str).add(' %')
>>> df 
   ID     col1     col2     col3    total
0   1  28.57 %  42.86 %  28.57 %  100.0 %
1   2  16.67 %  33.33 %   50.0 %  100.0 %
2   3   25.0 %   37.5 %   37.5 %  100.0 %
Answer from timgeb on Stack Overflow
๐ŸŒ
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....
Discussions

python - Convert column to percentage on Groupby - Stack Overflow
The column names are from variables ... are percentages of the total for each column, but I cant get it to work. ... FinancialYear 2014/2015 2015/2016 2016/2017 2017/2018 Month April 9% 6% 6% 24% May 7% 7% 6% 29% June 5% 10% 6% 24% July 6% 10% 5% 24% August 9% 8% 10% 0% September 9% 6% 12% 0% October 9% 10% 8% 0% November 10% 8% 9% 0% December 9% 11% 7% 0% January 9% 8% 10% 0% February 9% 7% 11% 0% March 9% 8% 10% 0% ... Edit: I tried the response found at this link: pandas convert columns to ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
September 8, 2017
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
python - Format certain floating dataframe columns into percentage in pandas - Stack Overflow
Is there a way to display a column as percentage without converting it to a string? 2020-06-09T19:15:00.443Z+00:00 ... Often times we are interested in calculating the full significant digits, but for the visual aesthetics, we may want to see only few decimal point when we display the dataframe. In jupyter-notebook, pandas ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
March 23, 2016
Format to Percent in Pandas ***HELP***
I would dare to say this is an excel problem, not a Python problem. More on reddit.com
๐ŸŒ r/learnpython
8
0
July 22, 2021
๐ŸŒ
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.
๐ŸŒ
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?

๐ŸŒ
Datasnips
datasnips.com โ€บ 164 โ€บ how-to-convert-dataframe-values-into-percentages
Python | How to Convert DataFrame Values Into Percentages | Datasnips
#PANDAS ยท #MATPLOTLIB ยท #SEABORN ยท LOGIN ยท PUBLIC SNIPPETS ยท LATEST SNIPPETS ยท TOP SNIPPETS ยท SNIPPET COLLECTIONS ยท ML CODE BUILDER ยท BLOG ยท Python ยท In this snippet we convert the values in the dataframe to the percentage each value represent across the row the row.
๐ŸŒ
XlsxWriter
xlsxwriter.readthedocs.io โ€บ example_pandas_percentage.html
Example: Pandas Excel output with percentage formatting โ€” XlsxWriter
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.
Find elsewhere
๐ŸŒ
Saturn Cloud
saturncloud.io โ€บ blog โ€บ how-to-calculate-percentage-with-pandas-dataframe
How to Calculate Percentage with Pandas DataFrame | Saturn Cloud Blog
December 7, 2023 - In this example, we first calculate the total number of each fruit sold using the sum() method of Pandas' DataFrame. We then divide each value in each column by the total and multiply by 100 to get the percentage.
๐ŸŒ
DataScience Made Simple
datasciencemadesimple.com โ€บ home โ€บ get the percentage of a column in pandas python
Get the percentage of a column in pandas python - DataScience Made Simple
February 5, 2023 - Percentage of a column in pandas dataframe is computed using sum() function and stored in a new column namely percentage as shown below ยท df1['percentage'] = df1['Mathematics_score']/df1['Mathematics_score'].sum() print(df1) ... With close to 10 years on Experience in data science and machine ...
๐ŸŒ
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) + "%"

๐ŸŒ
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.
๐ŸŒ
Skytowner
skytowner.com โ€บ explore โ€บ converting_percent_strings_into_numeric_in_pandas_dataframe
Converting percent strings into numeric in Pandas DataFrame
To convert percent strings into numeric type in Pandas DataFrame, first strip the trailing % character and then perform type conversion using astype(float).
๐ŸŒ
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 pandas library import pandas as pd # Dictionary df1 = { 'Name': ['abc', 'bcd', 'cde', 'def', 'efg', 'fgh', 'ghi'], 'Math_score': [52, 87, 49, 74, 28, 59, 48], 'Eng_score': [34, 67, 25, 89, 92, 45, 86] } # Create a DataFrame df1 = pd.DataFrame(df1, columns = ['Name', 'Math_score','Eng_score']) # Calculate Percentage df1['Eng_percent'] = (df1['Eng_score'] / df1['Eng_score'].sum()) * 100 # Show the dataframe df1
๐ŸŒ
Pandas
pandas.pydata.org โ€บ pandas-docs โ€บ stable โ€บ reference โ€บ api โ€บ pandas.DataFrame.pct_change.html
pandas.DataFrame.pct_change โ€” pandas 3.0.2 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....
๐ŸŒ
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:
Top answer
1 of 2
103

You were very close with your df attempt. Try changing:

df['col'] = df['col'].astype(float)

to:

df['col'] = df['col'].str.rstrip('%').astype('float') / 100.0
#                     ^ use str funcs to elim '%'     ^ divide by 100
# could also be:     .str[:-1].astype(...

Pandas supports Python's string processing functions on string columns. Just precede the string function you want with .str and see if it does what you need. (This includes string slicing, too, of course.)

Above we utilize .str.rstrip() to get rid of the trailing percent sign, then we divide the array in its entirety by 100.0 to convert from percentage to actual value. For example, 45% is equivalent to 0.45.

Although .str.rstrip('%') could also just be .str[:-1], I prefer to explicitly remove the '%' rather than blindly removing the last char, just in case...

2 of 2
63

You can define a custom function to convert your percents to floats at read_csv() time:

# dummy data
temp1 = """index col 
113 34%
122 50%
123 32%
301 12%"""

# Custom function taken from https://stackoverflow.com/questions/12432663/what-is-a-clean-way-to-convert-a-string-percent-to-a-float
def p2f(x):
    return float(x.strip('%'))/100

# Pass to `converters` param as a dict...
df = pd.read_csv(io.StringIO(temp1), sep='\s+',index_col=[0], converters={'col':p2f})
df

        col
index      
113    0.34
122    0.50
123    0.32
301    0.12

# Check that dtypes really are floats
df.dtypes

col    float64
dtype: object

My percent to float code is courtesy of ashwini's answer: What is a clean way to convert a string percent to a float?

๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ pandas โ€บ pandas percentage total with groupby
Pandas Percentage Total With Groupby - Spark By {Examples}
December 2, 2024 - You can calculate the percentage of the total within each group using DataFrame.groupby() along with DataFrame.agg(), DataFrame.transform(), and