You can convert most of the columns by just calling convert_objects:

CopyIn [36]:

df = df.convert_objects(convert_numeric=True)
df.dtypes
Out[36]:
Date         object
WD            int64
Manpower    float64
2nd          object
CTR          object
2ndU        float64
T1            int64
T2          int64
T3           int64
T4        float64
dtype: object

For column '2nd' and 'CTR' we can call the vectorised str methods to replace the thousands separator and remove the '%' sign and then astype to convert:

CopyIn [39]:

df['2nd'] = df['2nd'].str.replace(',','').astype(int)
df['CTR'] = df['CTR'].str.replace('%','').astype(np.float64)
df.dtypes
Out[39]:
Date         object
WD            int64
Manpower    float64
2nd           int32
CTR         float64
2ndU        float64
T1            int64
T2            int64
T3            int64
T4           object
dtype: object
In [40]:

df.head()
Out[40]:
        Date  WD  Manpower   2nd   CTR  2ndU   T1    T2   T3     T4
0   2013/4/6   6       NaN  2645  5.27  0.29  407   533  454    368
1   2013/4/7   7       NaN  2118  5.89  0.31  257   659  583    369
2  2013/4/13   6       NaN  2470  5.38  0.29  354   531  473    383
3  2013/4/14   7       NaN  2033  6.77  0.37  396   748  681    458
4  2013/4/20   6       NaN  2690  5.38  0.29  361   528  541    381

Or you can do the string handling operations above without the call to astype and then call convert_objects to convert everything in one go.

UPDATE

Since version 0.17.0 convert_objects is deprecated and there isn't a top-level function to do this so you need to do:

df.apply(lambda col:pd.to_numeric(col, errors='coerce'))

See the docs and this related question: pandas: to_numeric for multiple columns

Answer from EdChum on Stack Overflow
Top answer
1 of 7
49

You can convert most of the columns by just calling convert_objects:

CopyIn [36]:

df = df.convert_objects(convert_numeric=True)
df.dtypes
Out[36]:
Date         object
WD            int64
Manpower    float64
2nd          object
CTR          object
2ndU        float64
T1            int64
T2          int64
T3           int64
T4        float64
dtype: object

For column '2nd' and 'CTR' we can call the vectorised str methods to replace the thousands separator and remove the '%' sign and then astype to convert:

CopyIn [39]:

df['2nd'] = df['2nd'].str.replace(',','').astype(int)
df['CTR'] = df['CTR'].str.replace('%','').astype(np.float64)
df.dtypes
Out[39]:
Date         object
WD            int64
Manpower    float64
2nd           int32
CTR         float64
2ndU        float64
T1            int64
T2            int64
T3            int64
T4           object
dtype: object
In [40]:

df.head()
Out[40]:
        Date  WD  Manpower   2nd   CTR  2ndU   T1    T2   T3     T4
0   2013/4/6   6       NaN  2645  5.27  0.29  407   533  454    368
1   2013/4/7   7       NaN  2118  5.89  0.31  257   659  583    369
2  2013/4/13   6       NaN  2470  5.38  0.29  354   531  473    383
3  2013/4/14   7       NaN  2033  6.77  0.37  396   748  681    458
4  2013/4/20   6       NaN  2690  5.38  0.29  361   528  541    381

Or you can do the string handling operations above without the call to astype and then call convert_objects to convert everything in one go.

UPDATE

Since version 0.17.0 convert_objects is deprecated and there isn't a top-level function to do this so you need to do:

df.apply(lambda col:pd.to_numeric(col, errors='coerce'))

See the docs and this related question: pandas: to_numeric for multiple columns

2 of 7
41

convert_objects is deprecated.

For pandas >= 0.17.0, use pd.to_numeric

Copydf["2nd"] = pd.to_numeric(df["2nd"])
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › convert-pandas-dataframe-column-to-float
Convert Pandas Dataframe Column To Float - GeeksforGeeks
July 23, 2025 - Data types before conversion: ... the data type of the string column is changed from object to float after using to_numeric() function....
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 & ...
🌐
datagy
datagy.io › home › pandas tutorials › data analysis in pandas › converting pandas dataframe column from object to float
Converting Pandas DataFrame Column from Object to Float • datagy
May 12, 2023 - Let’s take a look at how we can convert a Pandas column to floats using the pd.to_numeric() function: # Convert a Pandas DataFrame Column to Float df['Price'] = pd.to_numeric(df['Price']) print(df.dtypes) # Returns: # Quantity int64 # Price ...
🌐
Saturn Cloud
saturncloud.io › blog › pandas-tips-change-column-type
How to change column type in Pandas | Saturn Cloud Blog
October 4, 2023 - To convert one or more columns to numeric values, pandas.to_numeric() is often a good option. This function will attempt to convert non-numeric values, such as strings, to either float64 or int64 depending on the input data.
🌐
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 - You can convert all numeric columns in a DataFrame to float using select_dtypes(). ... import pandas as pd numeric_cols = df.select_dtypes(include=["int64", "float64"]).columns df[numeric_cols] = df[numeric_cols].astype(float)
🌐
Statology
statology.org › home › how to convert object to float in pandas (with examples)
How to Convert Object to Float in Pandas (With Examples)
May 11, 2022 - #convert points column from object to float df['points'] = pd.to_numeric(df['points'], errors='coerce') #view updated DataFrame print(df) team points assists 0 A 18.0 5 1 B 22.2 7 2 C 19.1 7 3 D 14.0 9 4 E 14.0 12 5 F 11.5 9 6 G 20.0 9 7 H 28.0 4 #view updated data types print(df.dtypes) team object points float64 assists int64 dtype: object
🌐
Java2Blog
java2blog.com › home › python › pandas › convert object to float in pandas
Convert Object to Float in Pandas [2 Easy Ways] - Java2Blog
November 28, 2023 - Use the astype() method to convert the entire DataFrame from object to float in pandas. ... We used the astype() method to convert one column, multiple columns and the entire DataFrame’s dtypes from object to float.
Find elsewhere
🌐
Skytowner
skytowner.com › explore › converting_column_type_to_float_in_pandas_dataframe
Converting column type to float in Pandas DataFrame
We can map values that cannot be ... containing NaN to be of type float. To convert the data type of multiple columns to float, use Pandas' apply(~) method with to_numeric(~)....
🌐
Java2Blog
java2blog.com › home › python › pandas › pandas convert column to float
Pandas convert column to float - Java2Blog
May 26, 2020 - You can use asType(float) to convert string to float in Pandas. Here is the syntax: Here is an example. We will convert data type of Column Salary from integer to float64 ... You can use toNumeric() method where you might have non-numeric values in the column.
🌐
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
🌐
Reddit
reddit.com › r/learnpython › pandas dataframe columns won't convert to float
r/learnpython on Reddit: Pandas dataframe columns won't convert to float
May 14, 2022 -

I'm creating a pandas dataframe using US census data for a project I'm working on, and I'm having a problem converting the datatype of my columns to a numeric value. I've tried a couple different ways and keep running into the same issue.

dp03_emp = pd.read_csv('DP03_employment.csv',header=1).iloc[1:, :]

dp03_cleaned = dp03_emp[['Percent!!EMPLOYMENT STATUS!!Percent Unemployed',
                        'Estimate!!INCOME AND BENEFITS (IN 2011 INFLATION-ADJUSTED DOLLARS)!!Median household income (dollars)',
                        'Estimate!!INCOME AND BENEFITS (IN 2011 INFLATION-ADJUSTED DOLLARS)!!Mean household income (dollars)',
                        'Percent!!PERCENTAGE OF FAMILIES AND PEOPLE WHOSE INCOME IN THE PAST 12 MONTHS IS BELOW THE POVERTY LEVEL!!All people',
                        'Geographic Area Name',
                        'Survey Year']]

columns = ['Percent Unemployed','Median Household Income','Mean Household Income', 'Percent below poverty line']
dp03_cleaned[columns]=pd.to_numeric(columns,errors='coerce')

I know that using the 'coerce' argument will assign everything that is not recognized as a number either null or NaN, which is what happens to every value.

dp03_cleaned.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 20110 entries, 1 to 20110
Data columns (total 6 columns):
 #   Column                      Non-Null Count  Dtype  
---  ------                      --------------  -----  
 0   Percent Unemployed          0 non-null      float64
 1   Median Household Income     0 non-null      float64
 2   Mean Household Income       0 non-null      float64
 3   Percent below poverty line  0 non-null      float64
 4   Geographic Area Name        20109 non-null  object 
 5   Survey Year                 20109 non-null  float64
dtypes: float64(5), object(1)
memory usage: 942.8+ KB

I've also tried changing the datatype at the point of import in the read_csv dtype option, but it gives an error as well.

Sorry if this is a simple question, I've spent a fair bit of time trying to Google it and haven't had any luck. Thanks in advance for the help.

🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.astype.html
pandas.DataFrame.astype — pandas 3.0.3 documentation
Changed in version 2.0.0: Using astype to convert from timezone-naive dtype to timezone-aware dtype will raise an exception. Use Series.dt.tz_localize() instead. ... >>> d = {"col1": [1, 2], "col2": [3, 4]} >>> df = pd.DataFrame(data=d) >>> df.dtypes col1 int64 col2 int64 dtype: object ... >>> ser = pd.Series([1, 2], dtype="int32") >>> ser 0 1 1 2 dtype: int32 >>> ser.astype("int64") 0 1 1 2 dtype: int64 ... >>> from pandas.api.types import CategoricalDtype >>> cat_dtype = CategoricalDtype(categories=[2, 1], ordered=True) >>> ser.astype(cat_dtype) 0 1 1 2 dtype: category Categories (2, int64): [2 < 1]
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › how-to-convert-float64-columns-to-int64-in-pandas
How to Convert float64 Columns to int64 in Pandas? - GeeksforGeeks
July 23, 2025 - This enables the conversion of a column from various data types such as float or string to an integer type, specifically int64 or int32. We can use astype() method in Python to convert float64 Columns to int64 in Pandas.
🌐
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 - If we have done everything correctly, ... 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 ......
🌐
Sentry
sentry.io › sentry answers › python › change a column type in a dataframe in python pandas
Change a column type in a DataFrame in Python Pandas | Sentry
A B C 0 1 4 7 1 2 5 8 2 3 6 9 A object B object C object dtype: object Converted: A B C 0 1.0 4 7 1 2.0 5 8 2 3.0 6 9 A float64 B int64 C int64 dtype: object · If we want to convert a column to a numeric type, we can use the to_numeric function.
🌐
Practical Business Python
pbpython.com › pandas_dtypes.html
Overview of Pandas Data Types - Practical Business Python
Also of note, is that the function converts the number to a python float but pandas internally converts it to a float64. As mentioned earlier, I recommend that you allow pandas to convert to specific size float or int as it determines appropriate. There is no need for you to try to downcast to a smaller or upcast to a larger byte size unless you really know why you need to do it. Now, we can use the pandas apply function to apply this to all the values in the 2016 column.
🌐
Note.nkmk.me
note.nkmk.me › home › python › pandas
pandas: How to use astype() to cast dtype of DataFrame | note.nkmk.me
August 9, 2023 - df = pd.read_csv('data/src/sam... int64 # c float64 # d object # dtype: object ... If you specify a data type for the dtype argument, all columns are converted to that type....
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.to_numeric.html
pandas.to_numeric — pandas 3.0.3 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