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
๐ŸŒ
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
Discussions

python - pandas convert strings to float for multiple columns in dataframe - Stack Overflow
I'm new to pandas and trying to figure out how to convert multiple columns which are formatted as strings to float64's. Currently I'm doing the below, but it seems like apply() or applymap() shoul... More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - pandas how to convert all the string value to float - Stack Overflow
I want to convert all the string value in Pandas DataFrame into float, and I can define a short function to do this, but it's not a Pythonic way to do that. My DataFrame looks like this: >>&... More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - Convert strings to float in all pandas columns, where this is possible - Stack Overflow
13 pandas convert strings to float for multiple columns in dataframe More on stackoverflow.com
๐ŸŒ stackoverflow.com
January 30, 2018
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
People also ask

How do I convert a pandas column to float?
You can convert a pandas column to float using the astype() method. Example: df['column'] = df['column'].astype(float). This changes the column data type to float.
๐ŸŒ
golinuxcloud.com
golinuxcloud.com โ€บ home โ€บ databases โ€บ convert pandas dataframe column to float (astype, to_numeric & practical examples)
Convert pandas DataFrame Column to Float (astype, to_numeric & ...
How do I convert all columns in a pandas DataFrame to float?
You can convert all columns using apply(). Example: df = df.apply(pd.to_numeric, errors='coerce') which converts columns to numeric values including float.
๐ŸŒ
golinuxcloud.com
golinuxcloud.com โ€บ home โ€บ databases โ€บ convert pandas dataframe column to float (astype, to_numeric & practical examples)
Convert pandas DataFrame Column to Float (astype, to_numeric & ...
How do I convert an object column to float in pandas?
Object columns can be converted to float using pd.to_numeric() or astype(float). Example: df['column'] = pd.to_numeric(df['column']). This safely converts string values to numeric format.
๐ŸŒ
golinuxcloud.com
golinuxcloud.com โ€บ home โ€บ databases โ€บ convert pandas dataframe column to float (astype, to_numeric & practical examples)
Convert pandas DataFrame Column to Float (astype, to_numeric & ...
๐ŸŒ
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 - Example: In this example, we'll convert each value of the 'Inflation Rate' column to float. ... # importing pandas library import pandas as pd # creating a dictionary Data = {'Year': ['2016', '2017', '2018', '2019'], 'Inflation Rate': ['4.47', '5', '5.98', '4.1']} # create a dataframe df = pd.DataFrame(Data) # converting each value of column to a string df['Inflation Rate'] = pd.to_numeric(df['Inflation Rate']) # show the dataframe print(df) # show the data types print (df.dtypes)
๐ŸŒ
Statology
statology.org โ€บ home โ€บ how to convert strings to float in pandas
How to Convert Strings to Float in Pandas
November 28, 2022 - You can use the following methods to convert a string to a float in pandas: Method 1: Convert a Single Column to Float ยท #convert "assists" column from string to float df['assists'] = df['assists'].astype(float) Method 2: Convert Multiple Columns to Float ยท
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ pandas โ€บ convert-pandas-dataframe-column-to-float
Convert Pandas Dataframe Column To Float - GeeksforGeeks
July 23, 2025 - DataFrame.astype() method is used to cast a Pandas object to a specified dtype. astype() function is used to convert a particular column data type to another data type. Here, we created a sample data frame with two columns containing integers ...
Find elsewhere
๐ŸŒ
GoLinuxCloud
golinuxcloud.com โ€บ home โ€บ databases โ€บ convert pandas dataframe column to float (astype, to_numeric & practical examples)
Convert pandas DataFrame Column to Float (astype, to_numeric & Practical Examples) | GoLinuxCloud
March 9, 2026 - Learn how to convert pandas DataFrame columns to float using astype(), to_numeric(), and other practical methods. This tutorial explains how to convert string and object columns to float, handle invalid values, convert multiple columns, and safely process large datasets in pandas.
๐ŸŒ
Statistics Globe
statisticsglobe.com โ€บ home โ€บ python programming language for statistics & data science โ€บ convert string to float in pandas dataframe column in python (4 examples)
Convert String to Float in pandas DataFrame Column in Python (Example)
May 2, 2022 - After executing the previous syntax, a new pandas DataFrame called data_new1 has been created. Letโ€™s print the classes of all columns of this new data set: print(data_new1.dtypes) # Check data types of columns # x1 float64 # x2 object # x3 object # dtype: object ยท As you can see, we have changed the data type of the column x1 from object (or string) to the float64 class. It is also possible to transform multiple pandas DataFrame columns to the float data type.
๐ŸŒ
Skytowner
skytowner.com โ€บ explore โ€บ converting_column_type_to_float_in_pandas_dataframe
Converting column type to float in Pandas DataFrame
Note that Pandas will only allow columns containing NaN to be of type float. To convert the data type of multiple columns to float, use Pandas' apply(~) method with to_numeric(~).
๐ŸŒ
Arab Psychology
scales.arabpsychology.com โ€บ home โ€บ how can strings be converted to float in pandas?
How Can Strings Be Converted To Float In Pandas?
April 17, 2024 - One of the common tasks in data analysis is converting strings to float values, which is often necessary for performing mathematical operations. In Pandas, this can be achieved by using the astype() method, which allows users to specify the ...
Top answer
1 of 2
12

Assuming all values can be correctly converted to float, you can use DataFrame.astype() function to convert the type of complete dataframe to float. Example -

df = df.astype(float)

Demo -

In [5]: df = pd.DataFrame(np.array([['1', '2', '3'], ['4', '5', '6']]))

In [6]: df.astype(float)
Out[6]:
   0  1  2
0  1  2  3
1  4  5  6

In [7]: df = df.astype(float)

In [8]: df.dtypes
Out[8]:
0    float64
1    float64
2    float64
dtype: object

.astype() function also has a raise_on_error argument (which defaults to True) which you can set to False to make it ignore errors . In such cases, the original value is used in the DataFrame -

In [10]: df = pd.DataFrame([['1', '2', '3'], ['4', '5', '6'],['blah','bloh','bleh']])

In [11]: df.astype(float,raise_on_error=False)
Out[11]:
      0     1     2
0     1     2     3
1     4     5     6
2  blah  bloh  bleh

To convert just a series/column to float, again assuming all values can be converted, you can use [Series.astype()][2] . Example -

df['somecol'] = df['somecol'].astype(<type>)
2 of 2
6

Another option is to use df.convert_objects(numeric=True). It attempts to convert numeric strings to numbers, with unconvertible values becoming NaN:

import pandas as pd

df = pd.DataFrame([['1', '2', '3'], ['4', '5', 'foo'], ['bar', 'baz', 'quux']])
df = df.convert_objects(convert_numeric=True)
print(df)

yields

    0   1   2
0   1   2   3
1   4   5 NaN
2 NaN NaN NaN

In contrast, df.astype(float) would raise ValueError: could not convert string to float: quux since in the above DataFrame some strings (such as 'quux') is not numeric.

Note: in future versions of pandas (after 0.16.2) the function argument will be numeric=True instead of convert_numeric=True.

๐ŸŒ
Iditect
iditect.com โ€บ faq โ€บ python โ€บ converting-strings-to-floats-in-a-dataframe-in-python.html
Converting strings to floats in a DataFrame in python
To convert strings to floats in a DataFrame in Python using pandas, you can use the astype method or the pd.to_numeric function. Here's how you can do it: import pandas as pd # Sample DataFrame data = {'Column1': ['1.2', '2.3', '3.4'], 'Column2': ['4.5', '5.6', '6.7']} df = pd.DataFrame(data) ...
๐ŸŒ
Arabpsychology
statistics.arabpsychology.com โ€บ home โ€บ learning to convert string columns to float data types in pandas
Learning To Convert String Columns To Float Data Types In Pandas - PSYCHOLOGICAL STATISTICS
November 7, 2025 - Crucially, when reapplying the converted subset back to the original DataFrame, Pandas ensures that all columns are updated simultaneously, maintaining consistency across the structure. This bulk operation adheres to best practices for data processing pipelines by maximizing efficiency. #convert both "assists" and "rebounds" from strings to floats df[['assists', 'rebounds']] = df[['assists', 'rebounds']].astype(float)
๐ŸŒ
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.

๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ how can i parse values to float in a pandas dataframe column that contains both floats and strings?
r/learnpython on Reddit: How can I parse values to float in a pandas dataframe column that contains both floats and strings?
June 22, 2021 -

I have a pandas dataframe, populated using pandas.readcsv. Most of the values in the csv file are numeric, but there is one column of the csv, 'Parameter 3', which contains a couple of string values. Because of these 2 string values, every other value in this column is being interpreted as a string too.

I can deal with this using the following code, but it is not very elegant;

for i in df_distns.index:

    try:

        df_distns.loc[i, 'Parameter 3'] = float(df_distns.loc[i, 'Parameter 3'])

    except:

        pass  

Can anyone recommend a nicer way to do this (without looping)?

Top answer
1 of 8
162

UPDATE: you don't need to convert your values afterwards, you can do it on-the-fly when reading your CSV:

In [165]: df=pd.read_csv(url, index_col=0, na_values=['(NA)']).fillna(0)

In [166]: df.dtypes
Out[166]:
GeoName                    object
ComponentName              object
IndustryId                  int64
IndustryClassification     object
Description                object
2004                        int64
2005                        int64
2006                        int64
2007                        int64
2008                        int64
2009                        int64
2010                        int64
2011                        int64
2012                        int64
2013                        int64
2014                      float64
dtype: object

If you need to convert multiple columns to numeric dtypes - use the following technique:

Sample source DF:

In [271]: df
Out[271]:
     id    a  b  c  d  e    f
0  id_3  AAA  6  3  5  8    1
1  id_9    3  7  5  7  3  BBB
2  id_7    4  2  3  5  4    2
3  id_0    7  3  5  7  9    4
4  id_0    2  4  6  4  0    2

In [272]: df.dtypes
Out[272]:
id    object
a     object
b      int64
c      int64
d      int64
e      int64
f     object
dtype: object

Converting selected columns to numeric dtypes:

In [273]: cols = df.columns.drop('id')

In [274]: df[cols] = df[cols].apply(pd.to_numeric, errors='coerce')

In [275]: df
Out[275]:
     id    a  b  c  d  e    f
0  id_3  NaN  6  3  5  8  1.0
1  id_9  3.0  7  5  7  3  NaN
2  id_7  4.0  2  3  5  4  2.0
3  id_0  7.0  3  5  7  9  4.0
4  id_0  2.0  4  6  4  0  2.0

In [276]: df.dtypes
Out[276]:
id     object
a     float64
b       int64
c       int64
d       int64
e       int64
f     float64
dtype: object

PS if you want to select all string (object) columns use the following simple trick:

cols = df.columns[df.dtypes.eq('object')]
2 of 8
112

another way is using apply, one liner:

cols = ['col1', 'col2', 'col3']
data[cols] = data[cols].apply(pd.to_numeric, errors='coerce', axis=1)