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"])
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.convert_dtypes.html
pandas.DataFrame.convert_dtypes — pandas 3.0.3 documentation
>>> df.dtypes a int32 b object c object d object e float64 f float64 dtype: object · Convert the DataFrame to use best possible dtypes.
Discussions

python - How to transform the type of a column from object to float64? - Stack Overflow
Then, when I try to transform the type of an object column to float64, I get the error: "ValueError: could not convert string to float: '-1\xa0000.00 '" More on stackoverflow.com
🌐 stackoverflow.com
How do I convert a object to a float.
Can you post some sample data here? It sounds like one of your columns may contain strings of digits. In programming in general "2" and 2 are different. "2" != 2, but int("2") == 2. More on reddit.com
🌐 r/learnpython
3
2
April 7, 2022
python - How to convert object data type to Float64 and Int64 after updating the Pandas for interpolation for NAN values - Stack Overflow
I have updated my Anaconda environment and hence the associated libraries such as Pandas have been updated. I had a working code that now gives me the following error ValueError: Invalid fill method. More on stackoverflow.com
🌐 stackoverflow.com
python - Pandas convert data type from object to float - Stack Overflow
I read some weather data from a .csv file as a dataframe named "weather". The problem is that the data type of one of the columns is object. This is weird, as it indicates temperature. Ho... More on stackoverflow.com
🌐 stackoverflow.com
🌐
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 · Notice that the points column now has a data type of float64. Also note that this method produces the exact same result as the previous method. The following tutorials explain how to perform other common tasks in pandas: How to Convert Boolean Values to Integer Values in Pandas How to Convert DateTime to String in Pandas How to Convert Columns to int in Pandas
🌐
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....
🌐
Arab Psychology
scales.arabpsychology.com › home › how do i convert an object to a float in pandas?
How Do I Convert An Object To A Float In Pandas?
November 29, 2025 - Notice that the points column now has a data type of float64. The following code shows how to use the to_numeric() function to convert the points column in the DataFrame from an object to a float:
🌐
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 - One of the most common ways to convert a Pandas DataFrame column’s data type from object to float is to use the Pandas astype method. The astype method allows you to pass in a data type that you want to use.
🌐
Reddit
reddit.com › r/learnpython › how do i convert a object to a float.
r/learnpython on Reddit: How do I convert a object to a float.
April 7, 2022 -

Hi guys, im struggeling with my dataframe.

Im trying to get a percentage of 2 columns, but when I divide the 2 I get this error: unsupported operand type(s) for /: 'float' and 'str'

The dtypes of the columns are an 'object'

Im aware that I have empty data in my columns, but is that an issue?

Would appreciate your help!

Find elsewhere
🌐
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
🌐
Python Forum
python-forum.io › thread-2181.html
pandas convert to tuple & float to float64
Dear Pandas Experts, I got two question on my Introduction to Python homework. The jupiter auto-grader expects in case 1 a float64 and in case 2 a tuple, not a list. case 1 newfour_2['GDPDiff']=np.subtract(newfour['2015'],newfour['2006']) �...
🌐
Stack Overflow
stackoverflow.com › questions › 73228005 › how-to-convert-object-data-type-to-float64-and-int64-after-updating-the-pandas-f
python - How to convert object data type to Float64 and Int64 after updating the Pandas for interpolation for NAN values - Stack Overflow
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) Input In [6], in <cell line: 1>() ----> 1 df.interpolate(method ='linear', limit_direction ='backward', inplace=True) File ~\anaconda3\lib\site-packages\pandas\util\_decorators.py:311, in deprecate_nonkeyword_arguments.<locals>.decorate.<locals>.wrapper(*args, **kwargs) 305 if len(args) > num_allow_args: 306 warnings.warn( 307 msg.format(arguments=arguments), 308 FutureWarning, 309 stacklevel=stacklevel, 310 ) --> 311 return func(*args, **kwargs) File ~\anaconda3\lib\site-pa
🌐
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 one DataFrame column from object to float in pandas. ... Note that marks column has data type of float64.
🌐
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 ......
🌐
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.
🌐
GitHub
github.com › pandas-dev › pandas › issues › 17007
pd.to_numeric - float64, object or error? · Issue #17007 · pandas-dev/pandas
July 18, 2017 - import pandas as pd print pd.__version__ #different result example d = pd.DataFrame({'a':[200, 300, '', 'NaN', 10000000000000000000]}) #returns dtype object a = pd.to_numeric(d['a'], errors='coerce') print a.dtype #return dtype float64 b = d['a'].apply(pd.to_numeric, errors='coerce') print b.dtype #why not float64?
Author   pandas-dev
🌐
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.
🌐
GitHub
github.com › pola-rs › polars › issues › 8204
to_pandas converts polars Int64 to float64 instead of pandas Int64 when there are nulls · Issue #8204 · pola-rs/polars
April 13, 2023 - I would expected the columns to be converted to pandas Int64 instead of float64. import polars as pl; import pandas as pd; pandasdf = pd.DataFrame({ 'myint' :[1, None, 2]}) pandasdf['myint'] = pandasdf['myint'] .astype('Int64') print(pandasdf.dtypes) polarsdf = pl.from_pandas(pandasdf) print(polarsdf.dtypes) polarsToPandas = polarsdf.to_pandas() print(polarsToPandas.dtypes) output: myint Int64 dtype: object [Int64] #It gets converted to polars correctly myint float64 #It gets converted to pandas incorrectly.
Author   pola-rs
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.astype.html
pandas.DataFrame.astype — pandas 3.0.3 documentation
This method allows the conversion of the data types of pandas objects, including DataFrames and Series, to the specified dtype.