Use strip('%') , as:

In [9]: "99.5%".strip('%')
Out[9]: '99.5'             #convert this to float using float() and divide by 100

In [10]: def p2f(x):
   ....:    return float(x.strip('%'))/100
   ....: 

In [12]: p2f("99%")
Out[12]: 0.98999999999999999

In [13]: p2f("99.5%")
Out[13]: 0.995
Answer from Ashwini Chaudhary on Stack Overflow
🌐
w3resource
w3resource.com › python-exercises › string › python-data-type-string-exercise-36.php
Python: Format a number with a percentage - w3resource
print("Original Number: ", y) # Format the value of 'y' as a percentage with two decimal places and print it. print("Formatted Number with percentage: "+"{:.2%}".format(y)) # Print an empty line for spacing.
🌐
Reddit
reddit.com › r/learnpython › help with python code - convert string to percentage
r/learnpython on Reddit: Help With Python Code - Convert String to Percentage
May 6, 2021 -

Hello! I am very, very new to Python. I am working on an assignment for school and I am really struggling to get this string converted to a percentage. Can anyone help??

print(str("%.2f" % intensity).ljust(16) + str(max_hr))

🌐
Stack Abuse
stackabuse.com › python-string-interpolation-with-the-percent-operator
Python String Interpolation with the Percent (%) Operator
August 24, 2023 - Here we only have a single element to be used in our string formatting, and thus we're not required to enclose the element in a tuple like the previous examples. These placeholders represent a signed decimal integer. >>> year = 2019 >>> print("%i will be a perfect year." % year) 2019 will be a perfect year. Since this placeholder expects a decimal, it will be converted to one if a floating point value is provided instead.
🌐
Finxter
blog.finxter.com › home › learn python blog › how to print a percentage value in python?
How to Print a Percentage Value in Python? - Be on the Right Side of Change
May 31, 2022 - To print a percentage value in Python, use the str.format() method or an f-string on the format language pattern "{:.0%}". For example, the f-string f"{your_number:.0%}" will convert variable your_number to a percentage string with 0 digits precision. Simply run those three basic statements ...
🌐
Reddit
reddit.com › r/python › do you normally use string.format() or percentage (%) to format your python strings?
r/Python on Reddit: Do you normally use string.format() or percentage (%) to format your Python strings?
June 3, 2018 -

There are two ways of string formatting in python and I've been consistently using the percentage (%) method until now:

"Today is %s." % datetime.now() # 2018-06-03 16:50:35.226194
"%d is a good number." % 5 # 5

I know this may not be very eloquent, but does the job well. One of the major irritants for me is the number to string conversion, I've faced that error so many times in the earlier days when I simply used to "There are " + x + " mangoes.". This works great in most other languages as they "auto-convert" the x from integer to string, but not python because of its "explicitness". But today, I learned of this new method of string.format() which does the same job, perhaps more eloquently:

"Today is {0}.".format(datetime.now()) # 2018-06-03 16:50:35.226194 
"{0} is a good number.".format(5) # 5

The only problem I'd imagine would be when you have to deal with long floats:

f = 1.234535666
"this is a floating point number: {0}".format(f) # 1.234535666

Problem here is that it will output the entire float as it is without rounding, and here is where my percentage method has an edge!

"this is a floating point number: %.2f" % f # 1.23
🌐
GeeksforGeeks
geeksforgeeks.org › python-extract-percentages-from-string
Python - Extract Percentages from String - GeeksforGeeks
March 14, 2023 - The original string is : geeksforgeeks is 100% way to get 200% success The percentages : ['100%', '200%'] ... In this, we perform split of all words, and then from words that have %, we remove all non-numeric strings. This can be buggy in cases, we have different ordering of % and numbers in string. ... # Python3 code to demonstrate working of # Extract Percentages from String # Using re.sub() + split() import re # initializing strings test_str = 'geeksforgeeks is 100 % way to get 200 % success' # printing original string print("The original string is : " + str(test_str)) # extracting words temp = test_str.split() # using res = [] for sub in temp: if '%' in sub: # replace empty string to all non-number chars res.append(re.sub(r'[^\d, %]', '', sub)) # printing result print("The percentages : " + str(res))
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-convert-fraction-to-percent-in-python
How to convert fraction to percent in Python? - GeeksforGeeks
January 24, 2021 - In this article, we'll look at different ways to convert a string to a float in DataFrame. Creating Sample D ... By default, in Excel, the data points in the axis are in the form of integers or numeric representations. Sometimes we need to express these numeric data points in terms of percentages. So, Excel provides us an option to format from number representation to percentage. In this article, we are going ... Python defines type conversion functions to directly convert one data type to another.
🌐
Script Everything
scripteverything.com › posts › convert percentage string to decimal like 30% to 0.3 in python
Convert Percentage String To Decimal Like 30% To 0.3 In Python | Script Everything
February 10, 2022 - The Regex pattern that handles ... removed). To convert a percentage string to a decimal number use the built in function float with the replace string methods like so: float("30.0%".replace("%", ""))/100....
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?

🌐
AskPython
askpython.com › home › how to print a percentage value in python?
How To Print A Percentage Value In Python? - AskPython
April 21, 2023 - In this example 3, we use f-string ... value and the ‘:.0%‘ syntax will help to convert an original value into a percentage value. Let’s see the result. ... Here, let’s print the percentage value using f-string in Python....
🌐
Reddit
reddit.com › r/learnpython › how to turn decimal input into percentage
r/learnpython on Reddit: How to turn decimal input into percentage
October 1, 2020 -

So for my project one part of it is turning a decimal that as user would input and turn it into a decimal(It's supposed to be like a phone battery percentage). Im having trouble doing this so I need help. This is my input:

decimal = float(input("Enter a decimal: "))

So what would I code to turn whatever they put into a percent?

🌐
Medium
medium.com › @pivajr › pythonic-tips-how-to-format-percentage-values-in-python-bf9a5500d761
Pythonic Tips: How to Format Percentage Values in Python | by Dilermando Piva Junior | Medium
June 20, 2025 - The % symbol after the precision specifier acts like a translator: It multiplies the number by 100 and appends the percentage symbol. The number before % (like .1 or .2) controls decimal places— like adjusting the focus on a camera lens: more ...
🌐
Replit
replit.com › home › discover › how to calculate a percentage in python
How to calculate a percentage in Python | Replit
February 6, 2026 - The code translates the standard percentage formula—(value / total) * 100—directly into Python using basic arithmetic operators. Parentheses ensure the division operation happens first, which is essential for calculating the correct decimal ...
🌐
GeeksforGeeks
geeksforgeeks.org › different-ways-to-escape-percent-in-python-strings
Different Ways to Escape percent (%) in Python strings - GeeksforGeeks
September 5, 2024 - However, there are several ways that we can use to escape a percent (%) in the Python string. When using the old-style string formatting (also known as the printf-style), the percent sign is used as a placeholder. To include a literal percent sign in our string, we can escape it by doubling it, like so. In the example above, %d is a placeholder for an integer, and %% is used to insert a literal percent sign. The output correctly shows 50%. ... # Old-style string formatting percentage = 50 formatted_string = "The success rate is %d%%." % percentage print(formatted_string)
🌐
Kodeclik
kodeclik.com › how-to-make-decimal-to-percentage-python
How to convert a decimal to a percentage in Python
November 2, 2024 - To convert decimal to percentage, we can 1. Use simple multiplication. 2. Use string formatting, or 3. Use f-strings.
🌐
Quora
quora.com › How-do-I-calculate-percentage-in-python
How to calculate percentage in python - Quora
Python (programming langu... ... Development and Programmi... ... Calculating a percentage in Python is a simple arithmetic operation: percentage = (part / whole) * 100.
🌐
TestMu AI Community
community.testmuai.com › ask a question
How can I print a percentage value in Python? - Ask a Question - TestMu AI Community
December 23, 2024 - How can I print a percentage value in Python? Given a float between 0 and 1, how can I print it as a percentage? For example, 1/3 should print as 33%.