NOTE: pd.convert_objects has now been deprecated. You should use pd.Series.astype(float) or pd.to_numeric as described in other answers.

This is available in 0.11. Forces conversion (or set's to nan) This will work even when astype will fail; its also series by series so it won't convert say a complete string column

In [10]: df = DataFrame(dict(A = Series(['1.0','1']), B = Series(['1.0','foo'])))

In [11]: df
Out[11]: 
     A    B
0  1.0  1.0
1    1  foo

In [12]: df.dtypes
Out[12]: 
A    object
B    object
dtype: object

In [13]: df.convert_objects(convert_numeric=True)
Out[13]: 
   A   B
0  1   1
1  1 NaN

In [14]: df.convert_objects(convert_numeric=True).dtypes
Out[14]: 
A    float64
B    float64
dtype: object
Answer from Jeff on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-convert-strings-to-floats-in-pandas-dataframe
How to Convert String to Float in Pandas DataFrame - GeeksforGeeks
July 15, 2025 - Sometimes, we may not have a float value represented as a string. So, pd.to_numeric() function will show an error. To remove this error, we can use errors='coerce', to convert the value at this position to be converted to NaN.
Discussions

Pandas DataFrame tries to convert a string into a float, while adding it to a column
Well you're using np.nan which is a float. Interestingly though, it only raises the error after the first item has been added. >>> df = pd.DataFrame() >>> df['foo'] = [np.nan] * len(df) >>> df Empty DataFrame Columns: [foo] Index: [] Note the type is float64 >>> df.dtypes foo float64 dtype: object However, pandas converts it. >>> df.at['file_path', 'foo'] = 'file1' >>> df.dtypes foo object dtype: object Second time round, it raises the error - not sure why that is exactly. >>> df['bar'] = [np.nan] * len(df) >>> df.dtypes foo object bar float64 dtype: object >>> df.at['file_path', 'bar'] = 'file1' Traceback (most recent call last): You can use an empty string '' instead of np.nan - or you could initialize your dataframe with values. You may also want to check out pathlib from pathlib import Path file_paths = ... df = pd.DataFrame({ Path(p).stem: [p] for p in file_paths }) .stem from pathlib is the filename without the extension. More on reddit.com
🌐 r/learnpython
4
2
December 13, 2021
Could not convert string to float: ''
Hi to everybody, In pandas I want to convert a string column in a float one, but I get all the time the same error message: could not convert string to float: ‘’ The content of this column is the following: 2019-08-06T16:47:07.508 So I replaced “-”, “T”, “:” and “.” with ... More on discuss.python.org
🌐 discuss.python.org
0
0
June 6, 2024
Python pandas - can't convert string to float (I think b/c of multiple data types in column...)
Thanks u/Ihaveamodel3 for the solution, the original post was 95% of the way there. I added coerce & now it seems to work... dfteam1["cloff"] = pd.to_numeric(dfteam1["cloff"],errors='coerce') funny how coerce was needed. Thanks to u/omgu8mynewt for your reply as well. More on reddit.com
🌐 r/learnpython
5
1
July 17, 2022
python - Converting string to float using pandas - Stack Overflow
I have a csv file in which the column has '$' and ',' in it. So, I am unable to replace thementer image description here Please let me know if any solution available. Thank you. More on stackoverflow.com
🌐 stackoverflow.com
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas convert column to float in dataframe
Pandas Convert Column to Float in DataFrame - Spark By {Examples}
October 14, 2024 - You can use the Pandas DataFrame.astype() function to convert a column from string/int to float, you can apply this on a specific column or on an entire DataFrame. To cast the data type to a 54-bit signed float, you can use numpy.float64, ...
🌐
Statology
statology.org › home › how to convert strings to float in pandas
How to Convert Strings to Float in Pandas
November 28, 2022 - #convert all columns to float df = df.astype(float) #view column data types df.dtypes points float64 assists float64 rebounds float64 dtype: object · The following syntax shows how to convert the assists column from string to float and simultaneously fill in the NaN values with zeros:
🌐
Quora
quora.com › How-do-you-convert-a-string-to-a-float-in-pandas
How to convert a string to a float in pandas - Quora
If your talking about a single element, and assuming your using Python, you can just do something like this: a=”yourstring” yourfloat=float(a) finally you need to update your panda series, dataframe o...
🌐
Reddit
reddit.com › r/learnpython › pandas dataframe tries to convert a string into a float, while adding it to a column
r/learnpython on Reddit: Pandas DataFrame tries to convert a string into a float, while adding it to a column
December 13, 2021 -

Hello Guys,

I have a question regarding DataFrames. I have a line of code, which looks similar to this:

import os

import pandas as pd

import numpy as np

file_paths = ('C:/Users/DR/Documents/Polymer Science/Mitarbeiterpraktika/Forschungsmodul I Elektrochemie/Wasserspaltung/Co15-FTO_calc_WS_LS.txt', 'C:/Users/DR/Documents/Polymer Science/Mitarbeiterpraktika/Forschungsmodul I Elektrochemie/Wasserspaltung/Co16-FTO_calc_WS_LS.txt')

files_infos = pd.DataFrame()

for n, file_path in enumerate(file_paths) :

file_name = os.path.basename(file_path)

file_name = file_name.split(".txt")[0]

files_infos[file_name] = [np.nan] * len(files_infos)

files_infos.at["file_path", file_name] = file_path

If I run this script I get this Error. ValueError: could not convert string to float: 'C:/Users/DR/Documents/Polymer Science/Mitarbeiterpraktika/Forschungsmodul I Elektrochemie/Wasserspaltung/Co16-FTO_calc_WS_LS.txt'

I just don´t understand, why pandas tries to convert my string into a float. I thougt mabye it has something to do with the dtype of the DataFrame, but I couldn´t really find an answer (the dtype is object). What I find really confusing about this Error is, that I did use the same approach in different projects and it didn´t occur before.

Can someone of you mabye explain to me, why this error occurs and what I have to look up to find a solution? Please dont give me a solution to my problem, since I would like to solve it by myself in order to learn it.

Thank you for your help in advance.

🌐
Wellsr
wellsr.com › python › python-convert-pandas-dataframe-string-to-float-int
Python with Pandas: Convert String to Float and other Numeric Types - wellsr.com
November 9, 2018 - This method has the format [dtype2 ... to help it make more sense. Strings can be converted to floats using the astype method with the Numpy data type numpy.float64:...
Find elsewhere
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-convert-string-to-float
How to Convert String to Float in Python: Complete Guide with Examples | DigitalOcean
July 10, 2025 - Learn how to convert strings to floats in Python using float(). Includes syntax, examples, error handling tips, and real-world use cases for data parsing.
🌐
Saturn Cloud
saturncloud.io › blog › how-to-convert-a-column-in-pandas-dataframe-from-string-to-float
How to Convert a Column in Pandas DataFrame from String to Float | Saturn Cloud Blog
October 27, 2023 - Converting a column in a pandas DataFrame from a string to a float is a simple task that can be accomplished using the astype() method. In this blog post, we covered the steps required to convert a column from a string to a float.
🌐
Python.org
discuss.python.org › python help
Could not convert string to float: '' - Python Help - Discussions on Python.org
June 6, 2024 - Hi to everybody, In pandas I want to convert a string column in a float one, but I get all the time the same error message: could not convert string to float: ‘’ The content of this column is the following: 2019-08-06T16:47:07.508 So I replaced “-”, “T”, “:” and “.” with following code: climbing[“UTC time”] = climbing[“UTC time”].replace(“-”, “”, regex=True) climbing[“UTC time”] = climbing[“UTC time”].replace(“:”, “”, regex=True) climbing[“UTC time”] = climbing[“UTC time”].replace(“.”, “”,...
🌐
Reddit
reddit.com › r/learnpython › python pandas - can't convert string to float (i think b/c of multiple data types in column...)
r/learnpython on Reddit: Python pandas - can't convert string to float (I think b/c of multiple data types in column...)
July 17, 2022 -

I want to do some math on a dataframe but (I think) can't get one column/series into the necessary format. The column contains strings; some are '.123' while others are '0'. When I attempt the math on the column of strings by converting everything to an integer like so:

dfteam1['cloff'] = dfteam1.cloff.astype(int)

I get the following error

ValueError: invalid literal for int() with base 10: '.123'

I think it's b/c .123 isn't an integer but a float, so I change the code like so:

dfteam1['cloff'] = dfteam1.cloff.astype(float)

now I get the following error

ValueError: could not convert string to float:

I think it's b/c 0 isn't a float but an integer? Do I need to change all the 0 values to 0.00 or am I completely off base? All feedback is welcome.

🌐
Cherry Servers
cherryservers.com › home › blog › python › how to convert string to float in python (6 different ways)
How to Convert String to Float in Python (6 Different Ways) | Cherry Servers
July 25, 2024 - ... Using the float() function is the most common way to convert string to float in Python. What’s more, it is a built-in function which means it comes with standard Python installation.
🌐
Practical Business Python
pbpython.com › currency-cleanup.html
Cleaning Up Currency Data with Pandas - Practical Business Python
To illustrate the problem, and build the solution; I will show a quick example of a similar problem using only python data types. First, build a numeric and string variable. number = 1235 number_string = '$1,235' print(type(number_string), type(number)) ... This example is similar to our data in that we have a string and an integer. If we want to clean up the string to remove the extra characters and convert to a float:
🌐
GitHub
gist.github.com › Keiku › b3e0038a2d1145ea82eda8444b98c02a
Convert number strings with commas in pandas DataFrame to float. · GitHub
Convert number strings with commas in pandas DataFrame to float. - convert_number_strings_to_numbers.py
🌐
Statology
statology.org › home › how to fix in pandas: could not convert string to float
How to Fix in Pandas: could not convert string to float
July 16, 2022 - Notice that we’re able to convert the revenue column from a string to a float and we don’t receive any error since we removed the dollar signs before performing the conversion. The following tutorials explain how to fix other common errors in Python:
🌐
Stack Overflow
stackoverflow.com › questions › 74003247 › converting-string-to-float-using-pandas › 74003278
python - Converting string to float using pandas - Stack Overflow
Try dfnew['StartingMedianSalary'] = dfnew['StartingMedianSalary'].str.replace(',', '').str.replace('$', '').astype(float).
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.to_numeric.html
pandas.to_numeric — pandas 3.0.1 documentation - PyData |
Convert dtypes. ... >>> s = pd.Series(["1.0", "2", -3]) >>> pd.to_numeric(s) 0 1.0 1 2.0 2 -3.0 dtype: float64 >>> pd.to_numeric(s, downcast="float") 0 1.0 1 2.0 2 -3.0 dtype: float32 >>> pd.to_numeric(s, downcast="signed") 0 1 1 2 2 -3 dtype: int8 >>> s = pd.Series(["apple", "1.0", "2", -3]) >>> pd.to_numeric(s, errors="coerce") 0 NaN 1 1.0 2 2.0 3 -3.0 dtype: float64
🌐
Reddit
reddit.com › r/learnpython › how i convert float to string in this case?
r/learnpython on Reddit: How I convert float to string in this case?
August 21, 2022 -

I tried

n1=input('First number')
n2=input('Second number')
sum = float(n1) + float(n2)
str(sum)
print('The sum of the values is: ' + sum)

My error is:

TypeError: can only concatenate str (not "float") to str

I tried googling this error and got some answers like print(f' which I didn't really understand, and some others that looked a little complicated, I am very new.

I am trying to improve my googling skills.