All columns convertible

You can apply the function to all columns:

df.apply(pd.to_numeric)

Example:

>>> df = pd.DataFrame({'a': ['1', '2'], 
                       'b': ['45.8', '73.9'],
                       'c': [10.5, 3.7]})

>>> df.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 2 entries, 0 to 1
Data columns (total 3 columns):
a    2 non-null object
b    2 non-null object
c    2 non-null float64
dtypes: float64(1), object(2)
memory usage: 64.0+ bytes

>>> df.apply(pd.to_numeric).info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 2 entries, 0 to 1
Data columns (total 3 columns):
a    2 non-null int64
b    2 non-null float64
c    2 non-null float64
dtypes: float64(2), int64(1)
memory usage: 64.0 bytes

Not all columns convertible

pd.to_numeric has the keyword argument errors:

  Signature: pd.to_numeric(arg, errors='raise')
  Docstring:
  Convert argument to a numeric type.

Parameters
----------
arg : list, tuple or array of objects, or Series
errors : {'ignore', 'raise', 'coerce'}, default 'raise'
    - If 'raise', then invalid parsing will raise an exception
    - If 'coerce', then invalid parsing will be set as NaN
    - If 'ignore', then invalid parsing will return the input

Setting it to ignore will return the column unchanged if it cannot be converted into a numeric type.

As pointed out by Anton Protopopov, the most elegant way is to supply ignore as keyword argument to apply():

>>> df = pd.DataFrame({'ints': ['3', '5'], 'Words': ['Kobe', 'Bryant']})
>>> df.apply(pd.to_numeric, errors='ignore').info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 2 entries, 0 to 1
Data columns (total 2 columns):
Words    2 non-null object
ints     2 non-null int64
dtypes: int64(1), object(1)
memory usage: 48.0+ bytes

My previously suggested way, using partial from the module functools, is more verbose:

>>> from functools import partial
>>> df = pd.DataFrame({'ints': ['3', '5'], 
                       'Words': ['Kobe', 'Bryant']})
>>> df.apply(partial(pd.to_numeric, errors='ignore')).info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 2 entries, 0 to 1
Data columns (total 2 columns):
Words    2 non-null object
ints     2 non-null int64
dtypes: int64(1), object(1)
memory usage: 48.0+ bytes
Answer from Mike Müller on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › convert-a-dataframe-column-to-integer-in-pandas
Convert a Dataframe Column to Integer in Pandas - GeeksforGeeks
March 2, 2026 - This method is best when the data is clean, and you are sure that all values in the column can be successfully converted to integers without any errors. ... import pandas as pd # Creating a sample DataFrame data = {'Column1': ['1', '2', '3', '4']} df = pd.DataFrame(data) df['Column1'] = df['Column1'].astype(int) print(df) print(df['Column1'].dtype)
Top answer
1 of 4
150

All columns convertible

You can apply the function to all columns:

df.apply(pd.to_numeric)

Example:

>>> df = pd.DataFrame({'a': ['1', '2'], 
                       'b': ['45.8', '73.9'],
                       'c': [10.5, 3.7]})

>>> df.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 2 entries, 0 to 1
Data columns (total 3 columns):
a    2 non-null object
b    2 non-null object
c    2 non-null float64
dtypes: float64(1), object(2)
memory usage: 64.0+ bytes

>>> df.apply(pd.to_numeric).info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 2 entries, 0 to 1
Data columns (total 3 columns):
a    2 non-null int64
b    2 non-null float64
c    2 non-null float64
dtypes: float64(2), int64(1)
memory usage: 64.0 bytes

Not all columns convertible

pd.to_numeric has the keyword argument errors:

  Signature: pd.to_numeric(arg, errors='raise')
  Docstring:
  Convert argument to a numeric type.

Parameters
----------
arg : list, tuple or array of objects, or Series
errors : {'ignore', 'raise', 'coerce'}, default 'raise'
    - If 'raise', then invalid parsing will raise an exception
    - If 'coerce', then invalid parsing will be set as NaN
    - If 'ignore', then invalid parsing will return the input

Setting it to ignore will return the column unchanged if it cannot be converted into a numeric type.

As pointed out by Anton Protopopov, the most elegant way is to supply ignore as keyword argument to apply():

>>> df = pd.DataFrame({'ints': ['3', '5'], 'Words': ['Kobe', 'Bryant']})
>>> df.apply(pd.to_numeric, errors='ignore').info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 2 entries, 0 to 1
Data columns (total 2 columns):
Words    2 non-null object
ints     2 non-null int64
dtypes: int64(1), object(1)
memory usage: 48.0+ bytes

My previously suggested way, using partial from the module functools, is more verbose:

>>> from functools import partial
>>> df = pd.DataFrame({'ints': ['3', '5'], 
                       'Words': ['Kobe', 'Bryant']})
>>> df.apply(partial(pd.to_numeric, errors='ignore')).info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 2 entries, 0 to 1
Data columns (total 2 columns):
Words    2 non-null object
ints     2 non-null int64
dtypes: int64(1), object(1)
memory usage: 48.0+ bytes
2 of 4
7

The accepted answer with pd.to_numeric() converts to float, as soon as it is needed. Reading the question in detail, it is about converting any numeric column to integer. That is why the accepted answer needs a loop over all columns to convert the numbers to int in the end.

Just for completeness, this is even possible without pd.to_numeric(); of course, this is not recommended:

df = pd.DataFrame({'a': ['1', '2'], 
                   'b': ['45.8', '73.9'],
                   'c': [10.5, 3.7]})

for i in df.columns:
    try:
        df[[i]] = df[[i]].astype(float).astype(int)
    except:
        pass

print(df.dtypes)

Out:

a    int32
b    int32
c    int32
dtype: object

EDITED: Mind that this not recommended solution is unnecessarily complicated; pd.to_numeric() can simply use the keyword argument downcast='integer' to force integer as output, thank you for the comment. This is then still missing in the accepted answer, though.

News again From a comment by user Gary, it turns out that "as of pandas 2.0.1, if input series contains empty string or None then the resulting dtype will still be float even when using downcast='integer'". That would mean that the first answer with .astype(float).astype(int) is alive again if you want to be sure to get only integers.

🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.to_numeric.html
pandas.to_numeric — pandas 3.0.6 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
🌐
GoLinuxCloud
golinuxcloud.com › home › databases › pandas › 7 ways to convert pandas dataframe column to int
7 ways to convert pandas DataFrame column to int | GoLinuxCloud
January 24, 2022 - In this tutorial we will discuss how to convert DataFrame columns into int using the following methods: If calculations require decimal values rather than whole numbers, use the pandas column-to-float guide for astype(float), to_numeric(), invalid values, and float32 versus float64.
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas convert column to int in dataframe
Pandas Convert Column to Int in DataFrame - Spark By {Examples}
June 26, 2025 - How to convert the Pandas column to int in DataFrame? You can use DataFrame.astype(int) or DataFrame.apply() method to convert a column to int
🌐
GeeksforGeeks
geeksforgeeks.org › convert-floats-to-integers-in-a-pandas-dataframe
Convert Floats to Integers in a Pandas DataFrame - GeeksforGeeks
December 1, 2023 - Converting DataFrame columns to ... in a Pandas DataFrameConvert DataFrame Column to Integer - using astype() Methodastype() method is simple...
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-convert-string-to-integer-in-pandas-dataframe
How to Convert String to Integer in Pandas DataFrame? - GeeksforGeeks
July 15, 2025 - # import pandas library import pandas as pd # dictionary Data = {'Name': ['GeeksForGeeks','Python'], 'Unique ID': ['900','450']} # create a dataframe object df = pd.DataFrame(Data) # convert string to an integer df['Unique ID'] = df['Unique ID'].astype(int) # show the dataframe print (df) print("-"*25) # show the data types # of each columns print (df.dtypes) Output : Example 2: Python3 ·
Find elsewhere
🌐
Arab Psychology
scales.arabpsychology.com › home › how to easily convert dataframe columns to integers in pandas
How To Easily Convert DataFrame Columns To Integers In Pandas
December 4, 2025 - To convert columns of a Pandas DataFrame to int, you can use the astype() method. This method takes as an argument the specific data type to which the column should be converted. For example, to convert a column currently stored as strings (object) ...
🌐
TutorialsPoint
tutorialspoint.com › article › how-to-convert-string-to-integer-in-pandas-dataframe
How to Convert String to Integer in Pandas DataFrame?
March 27, 2026 - Use astype(int) for clean string data that you're confident contains only valid integers. Use pd.to_numeric() with errors='coerce' for data that may contain invalid values, as it provides better error handling and converts problematic values to NaN.
🌐
Statology
statology.org › home › how to convert pandas dataframe columns to int
How to Convert Pandas DataFrame Columns to int
November 28, 2022 - We can see that the ‘points’ column is now an integer, while all other columns remained unchanged. The following code shows how to convert multiple columns in a DataFrame to an integer:
🌐
Pandas
pandas.pydata.org › pandas-docs › stable › reference › api › pandas.to_numeric.html
pandas.to_numeric — pandas 3.0.2 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
🌐
YouTube
youtube.com › watch
Convert String to Integer in pandas DataFrame Column in Python (Examples) | astype() & to_numeric() - YouTube
How to transform a pandas DataFrame column from string to integer in the Python programming language. More details: https://statisticsglobe.com/convert-strin...
Published: September 5, 2022
🌐
Saturn Cloud
saturncloud.io › blog › pandas-convert-string-to-int-a-guide-for-data-scientists
Pandas Convert String to Int A Guide for Data Scientists | Saturn Cloud Blog
May 1, 2026 - To convert a string to an integer using Pandas, you can use the astype() method. This method is available on Pandas Series and DataFrame objects and can be used to convert the data type of a column from one type to another.
🌐
Appdividend
appdividend.com › converting-floats-to-integers-in-a-pandas-dataframe
How to Convert Floats to Integers in a Pandas DataFrame
September 7, 2025 - The efficient way to convert floating-point numbers to integers in Pandas is by using the “.astype()” function. It truncates the decimal part of the float, and it doesn’t round. So, 2.99 becomes 2, not 3. ... Here, ‘df’ is the input DataFrame, ‘col’ is the column of that DataFrame, and ‘int’ is the integer type.
🌐
IncludeHelp
includehelp.com › python › convert-entire-pandas-dataframe-to-integers.aspx
Python - Convert entire pandas dataframe to integers
This method is used when we want to convert the data type of one single column or a series, but if we want to convert the entire DataFrame, for this purpose, we have a method called pandas.to_numeric() method but again it fails in case of float values and hence we have to loop over the columns ...
🌐
Bobby Hadz
bobbyhadz.com › blog › pandas-convert-entire-dataframe-to-numeric-integers-or-floats
Pandas: Convert entire DataFrame to numeric (int or float) | bobbyhadz
April 12, 2024 - The to_numeric() method will convert the values in the DataFrame to int or float, depending on the supplied values.
🌐
Medium
medium.com › @amit25173 › pandas-float-to-int-a-practical-guide-a288ab2fe3d9
Pandas Float to Int: A Practical Guide | by Amit Yadav | Medium
March 6, 2025 - 2. What is the best method for converting floats to integers? ... Yes, especially in large datasets. Using downcast=”integer” reduces memory usage significantly, which can improve processing speed. 4. How do I convert a whole DataFrame instead of a single 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.
🌐
Saturn Cloud
saturncloud.io › blog › how-to-read-rows-and-convert-float-to-integer-in-pandas
How to Read Rows and Convert Float to Integer in Pandas | Saturn Cloud Blog
May 1, 2026 - In the above example, we converted the values in Column1 from float to integer using the astype() method. We then printed the data types of all columns in the DataFrame using the dtypes attribute, which shows us that Column1 is now an integer.