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.astype.html
pandas.DataFrame.astype — pandas 3.0.3 documentation
Use a str, numpy.dtype, pandas.ExtensionDtype or Python type to cast entire pandas object to the same type. Alternatively, use a mapping, e.g. {col: dtype, …}, where col is a column label and dtype is a numpy.dtype or Python type to cast one or more of the DataFrame’s columns to column-specific types. ... This keyword is now ignored; changing its value will have no impact on the method.
🌐
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 - print(df_mix.loc['A']) # col_int 0.0 # col_float 0.0 # Name: A, dtype: float64 print(df_mix.T) # A B C # col_int 0.0 1.0 2.0 # col_float 0.0 0.1 0.2 print(df_mix.T.dtypes) # A float64 # B float64 # C float64 # dtype: object ... The data type may also be implicitly converted when assigning a value to an element. For example, assigning a float value to an element in the int column converts that column to float, while assigning an int value to an element in the float column retains the float type for that element.
🌐
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'] = df['points'].astype(float) #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
🌐
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....
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-convert-integers-to-floats-in-pandas-dataframe
How to Convert Integers to Floats in Pandas DataFrame? | GeeksforGeeks
August 25, 2020 - In the above example, we change the data type of column 'Weight' from 'int64' to 'float64'. Example 2: Converting more than one column from int to float using DataFrame.astype() ... # importing pandas library import pandas as pd # Initializing the nested list with Data set player_list = [['M.S.Dhoni', 36, 75, 5428000, 176], ['A.B.D Villers', 38, 74, 3428000, 175], ['V.Kholi', 31, 70, 8428000, 172], ['S.Smith', 34, 80, 4428000, 180], ['C.Gayle', 40, 100, 4528000, 200], ['J.Root', 33, 72, 7028000, 170], ['K.Peterson', 42, 85, 2528000, 190]] # creating a pandas dataframe df = pd.DataFrame(player_list, columns=[ 'Name', 'Age', 'Weight', 'Salary', 'Strike_rate']) # lets find out the data type of 'Age' # and 'Strike_rate' columns print(df.dtypes)
Find elsewhere
🌐
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.
🌐
Skytowner
skytowner.com › explore › converting_column_type_to_float_in_pandas_dataframe
Converting column type to float in Pandas DataFrame
Pandas to_numeric(~) method converts the input to a numerical type. By default, either int64 or float64 will be used. chevron_right · Pandas DataFrame | astype method · Pandas DataFrame.astype(~) method converts the data type of the columns of a DataFrame to the specified type.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.to_numeric.html
pandas.to_numeric — pandas 3.0.3 documentation - PyData |
>>> s = pd.Series([1, 2, 3], dtype="Int64") >>> pd.to_numeric(s, downcast="integer") 0 1 1 2 2 3 dtype: Int8 >>> s = pd.Series([1.0, 2.1, 3.0], dtype="Float64") >>> pd.to_numeric(s, downcast="float") 0 1.0 1 2.1 2 3.0 dtype: Float32
🌐
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
Top answer
1 of 5
125

Solution for pandas 0.24+ for converting numeric with missing values:

df = pd.DataFrame({'column name':[7500000.0,7500000.0, np.nan]})
print (df['column name'])
0    7500000.0
1    7500000.0
2          NaN
Name: column name, dtype: float64

df['column name'] = df['column name'].astype(np.int64)

ValueError: Cannot convert non-finite values (NA or inf) to integer

#http://pandas.pydata.org/pandas-docs/stable/user_guide/integer_na.html
df['column name'] = df['column name'].astype('Int64')
print (df['column name'])
0    7500000
1    7500000
2        NaN
Name: column name, dtype: Int64

I think you need cast to numpy.int64:

df['column name'].astype(np.int64)

Sample:

df = pd.DataFrame({'column name':[7500000.0,7500000.0]})
print (df['column name'])
0    7500000.0
1    7500000.0
Name: column name, dtype: float64

df['column name'] = df['column name'].astype(np.int64)
#same as
#df['column name'] = df['column name'].astype(pd.np.int64)
print (df['column name'])
0    7500000
1    7500000
Name: column name, dtype: int64

If some NaNs in columns need replace them to some int (e.g. 0) by fillna, because type of NaN is float:

df = pd.DataFrame({'column name':[7500000.0,np.nan]})

df['column name'] = df['column name'].fillna(0).astype(np.int64)
print (df['column name'])
0    7500000
1          0
Name: column name, dtype: int64

Also check documentation - missing data casting rules

EDIT:

Convert values with NaNs is buggy:

df = pd.DataFrame({'column name':[7500000.0,np.nan]})

df['column name'] = df['column name'].values.astype(np.int64)
print (df['column name'])
0                7500000
1   -9223372036854775808
Name: column name, dtype: int64
2 of 5
12

You can need to pass in the string 'int64':

>>> import pandas as pd
>>> df = pd.DataFrame({'a': [1.0, 2.0]})  # some test dataframe

>>> df['a'].astype('int64')
0    1
1    2
Name: a, dtype: int64

There are some alternative ways to specify 64-bit integers:

>>> df['a'].astype('i8')      # integer with 8 bytes (64 bit)
0    1
1    2
Name: a, dtype: int64

>>> import numpy as np
>>> df['a'].astype(np.int64)  # native numpy 64 bit integer
0    1
1    2
Name: a, dtype: int64

Or use np.int64 directly on your column (but it returns a numpy.array):

>>> np.int64(df['a'])
array([1, 2], dtype=int64)
🌐
Pandas
pandas.pydata.org › pandas-docs › stable › reference › api › pandas.DataFrame.astype.html
pandas.DataFrame.astype — pandas 3.0.1 documentation
This method allows the conversion of the data types of pandas objects, including DataFrames and Series, to the specified dtype. It supports casting entire objects to a single data type or applying different data types to individual columns using a mapping.
🌐
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.
🌐
LinkedIn
linkedin.com › pulse › change-data-type-columns-pandas-mohit-sharma
Change the data type of columns in Pandas
February 8, 2021 - The best way to convert one or more columns of a DataFrame to numeric values is to use pandas.to_numeric(). This function will try to change non-numeric objects (such as strings) into integers or floating-point numbers as appropriate.
🌐
Medium
medium.com › @filip.sekan › 3-ways-how-to-update-data-type-of-columns-in-pandas-97ddb5f32ae4
3 ways how to update data type of columns in Pandas | by Filip Sekan | Medium
February 3, 2023 - It’s also possible to change the data type of multiple columns in a dataframe using the astype() method. Here's an example: ... In this example, the data type of both the ‘age’ and ‘salary’ columns has been changed to ‘float64’...
🌐
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 - The most straightforward way to convert a pandas column to float is using the astype() method. This method explicitly casts the column data type to float. ... import pandas as pd df = pd.DataFrame({ "price": [10, 20, 30, 40] }) df["price"] = ...
🌐
CodeSignal
codesignal.com › learn › courses › cleaning-and-transforming-data-with-pandas › lessons › data-type-conversion-in-pandas
Data Type Conversion in Pandas
Pandas provides a powerful method, astype, to transform the data type of a column swiftly and efficiently. Let’s see how astype can be utilized: ... In this segment, the conversion ensures that the 'Age' column changes to integer and the 'Salary' column to float. Now, let's delve deeper into understanding the difference between int32, float32 and int64, float64...
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › pandas-change-datatype
Pandas Change Datatype - GeeksforGeeks
July 23, 2025 - If you need to change the data types of multiple columns at once, you can pass a dictionary to the astype() method, where keys are column names and values are the desired data types.