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

CopyIn [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

python - Convert Float to String in Pandas - Stack Overflow
Since pandas 1.0, there's a new 'string' dtype where you can keep a Nullable integer dtype after casting a column into a 'string' dtype. For example, if you want to convert floats to strings without decimals, yet the column contains NaN values that you want to keep as null, you can use 'string' ... More on stackoverflow.com
🌐 stackoverflow.com
How I convert float to string in this case?
You shouldn't call your variable sum, as that's a name of a built in function: https://docs.python.org/3/library/functions.html#sum Your problem however, stems from trying to add a string to a float. Could you please tell me, what is Adam + 5? Well, you can't, because it makes no mathematical sense. You didn't save the string representation str(sum), so sum never changed to a string What your research found is f-strings and they are very easy to use. Try: print(f"the sum of the values is {sum}") Simply, put an f before a string starts, then any string that you want goes between " and ", while any variables or other values go between { and } More on reddit.com
🌐 r/learnpython
4
2
August 21, 2022
python - Trying to convert a column with strings to float via Pandas - Stack Overflow
Hi I have looked but on stackoverflow and not found a solution for my problem. Any help highly appeciated. After importing a csv I noticed that all the types of the columns are object and not floa... More on stackoverflow.com
🌐 stackoverflow.com
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
2
July 17, 2022
🌐
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.

🌐
Statology
statology.org › home › how to convert strings to float in pandas
How to Convert Strings to Float in Pandas
November 28, 2022 - A simple explanation of how to convert string columns in a pandas DataFrame to float columns.
🌐
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
June 19, 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.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.convert_dtypes.html
pandas.DataFrame.convert_dtypes — pandas 3.0.3 documentation
By default, convert_dtypes will attempt to convert a Series (or each Series in a DataFrame) to dtypes that support pd.NA. By using the options convert_string, convert_integer, convert_boolean and convert_floating, it is possible to turn off individual conversions to StringDtype, the integer extension types, BooleanDtype or floating extension types, respectively.
Find elsewhere
🌐
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 - By using pandas DataFrame.astype() and pandas.to_numeric() methods you can convert a column from string/int type to float. In this article, I will explain
🌐
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.
🌐
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 ...
🌐
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.
🌐
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:...
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › how-to-handle-pandas-value-error-could-not-convert-string-to-float
How To Handle Pandas Value Error : Could Not Convert String To Float - GeeksforGeeks
July 23, 2025 - For instance, our string contains both numeric and special characters then apply() method allows us to convert the numeric part of the string into float with a custom expression. ... import pandas as pd # Creating some data with strings containing ...
Top answer
1 of 2
38

If a column contains string or is treated as string, it will have a dtype of object (but not necessarily true backward -- more below). Here is a simple example:

import pandas as pd
df = pd.DataFrame({'SpT': ['string1', 'string2', 'string3'],
                   'num': ['0.1', '0.2', '0.3'],
                   'strange': ['0.1', '0.2', 0.3]})
print df.dtypes
#SpT        object
#num        object
#strange    object
#dtype: object

If a column contains only strings, we can apply len on it like what you did should work fine:

print df['num'].apply(lambda x: len(x))
#0    3
#1    3
#2    3

However, a dtype of object does not means it only contains strings. For example, the column strange contains objects with mixed types -- and some str and a float. Applying the function len will raise an error similar to what you have seen:

print df['strange'].apply(lambda x: len(x))
# TypeError: object of type 'float' has no len()

Thus, the problem could be that you have not properly converted the column to string, and the column still contains mixed object types.

Continuing the above example, let us convert strange to strings and check if apply works:

df['strange'] = df['strange'].astype(str)
print df['strange'].apply(lambda x: len(x))
#0    3
#1    3
#2    3

(There is a suspicious discrepancy between df_cleaned and df_clean there in your question, is it a typo or a mistake in the code that causes the problem?)

2 of 2
1
"Hidden" nulls

If the column dtype is object, TypeError: object of type 'float' has no len() often occurs if the column contains NaN. Check if that's the case by calling

df['Col2'].isna().any()

If it returns True, then there's NaN and you probably need to handle that.


Vectorized str. methods

If null handling is not important, you can also call vectorized str.len(), str.isdigit() etc. methods. For example, the code in the OP can be written as:

df['Col3'] = df['Col2'].str.len().ge(2) & df['Col2'].str[0].str.isalpha()

to get the desired output without errors.


'string' dtype

Since pandas 1.0, there's a new 'string' dtype where you can keep a Nullable integer dtype after casting a column into a 'string' dtype. For example, if you want to convert floats to strings without decimals, yet the column contains NaN values that you want to keep as null, you can use 'string' dtype.

df = pd.DataFrame({
    'Col1': [1.2, 3.4, 5.5, float('nan')]
})

df['Col1'] = df['Col1'].astype('string').str.split('.').str[0]

returns

0       1
1       3
2       5
3    <NA>
Name: Col1, dtype: object

where <NA> is a Nullable integer that you can drop with dropna() while df['Col1'].astype(str) casts NaNs into strings.

🌐
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.

🌐
YouTube
youtube.com › dr. vytautas bielinskas
Pandas Trick. Convert Strings to Float in Pandas DataFrame (parsing data with RegEx) - YouTube
With this video I demonstrate how to extract or convert numerical data (digits) from Pandas DataFrame to Float type values in whole data structure. This is a...
Published   September 28, 2019
Views   7K
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas convert floats to strings in dataframe
Pandas Convert Floats to Strings in DataFrame - Spark By {Examples}
December 5, 2024 - To convert floats to strings in a Pandas DataFrame, you can use the DataFrame.astype() function and the DataFrame.apply() method. These tools enable you
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-convert-floats-to-strings-in-pandas-dataframe
How to Convert Floats to Strings in Pandas DataFrame? - GeeksforGeeks
July 15, 2025 - There are three methods to convert Float to String: Method 1: Using DataFrame.astype(). ... This is used to cast a pandas object to a specified dtype.
🌐
Medium
louwersj.medium.com › solved-valueerror-could-not-convert-string-to-float-afbc5c3828e7
Solved: ValueError: could not convert string to float: ‘’ | by Johan Louwers | Medium
September 23, 2022 - This is used to cast a pandas object to a specified dtype. In our example we try to transform this into a float64 as show in the example below where we try to transform “avg_use” into a float. ... In general this method works quite well, the exception to this is that you might run into a ValueError as shown below. This commonly is the case if your dataset is not clean and “avg_use” contains values that are not able to be converted to a float.