.astype() is a method within numpy.ndarray, as well as the Pandas Series class, so can be used to convert vectors, matrices and columns within a DataFrame. However, int() is a pure-Python function that can only be applied to scalar values.

For example, you can do int(3.14), but can't do (2.7).astype('int'), because Python native types don't have any such method. However, numpy.array([1.1, 2.2, 3.3]).astype('int') is valid.

(Strictly, it is also possible to define an __int__() method within one's own classes, which would allow int() to be applied to non-native types. Thanks to @juanpa.arrivillaga for pointing this out.)

Answer from rwp on Stack Overflow
🌐
Medium
medium.com › @heyamit10 › understanding-pandas-astype-with-examples-f1b21ad17e69
Understanding pandas astype() with Examples | by Hey Amit | Medium
March 6, 2025 - Using astype(int), we converted them to integers (1, 2), and yes—it truncates the decimal part without rounding.
🌐
DEV Community
dev.to › atifwattoo › what-is-astype-function-in-python-4bg5
What is astype() function in Python - DEV Community
January 8, 2025 - df = pd.DataFrame({'A': ['1', 'two', '3'], 'B': [1.5, 2.5, 3.5]}) # Attempt conversion with errors='ignore' df['A'] = df['A'].astype(int, errors='ignore') print(df) ... Conversion fails for 'two', but no error is raised. import numpy as np # Example array arr = np.array([1.1, 2.2, 3.3]) # Convert to integer arr_int = arr.astype(int) print(arr_int)
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-pandas-dataframe-astype
Pandas DataFrame.astype()-Python - GeeksforGeeks
June 26, 2025 - DataFrame.astype(dtype, copy=True, errors='raise') ... Returns: A new DataFrame or Series with updated data types. Example 1: In this, we convert column 'A' to integer, while column 'B' remains unchanged.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.astype.html
pandas.DataFrame.astype — pandas 3.0.6 documentation
>>> ser = pd.Series([1, 2], dtype="int32") >>> ser 0 1 1 2 dtype: int32 >>> ser.astype("int64") 0 1 1 2 dtype: int64
🌐
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: # Convert 'Age' to integer df['Age'] = df['Age'].astype(int) print(df['Age'].dtype) # Convert 'Salary' to float df['Salary'] = df['Salary'].astype(float) print(df['Salary'].dtype)
🌐
Favtutor
favtutor.com › articles › pandas-convert-column-to-int
Convert the data type of Pandas column to int (with code)
December 29, 2023 - To convert a single column to the integer data type, we can use the astype() method. First, access the column using the column name and then apply the conversion.
Find elsewhere
🌐
Programiz
programiz.com › python-programming › numpy › methods › astype
NumPy astype()
import numpy as np # original array of integers with big-endian byte order array1 = np.array([1, 2, 3, 4, 5], dtype='>i4') # casting with 'no' doesn't allow casting to any other data type array2 = array1.astype(array1.dtype, casting='no') # casting with 'equiv' allows casting to equivalent data types array3 = array1.astype('<i4', casting='equiv') #cCasting with 'safe' allows casting to safe data types preserving precision array4 = array1.astype(np.float64, casting='safe') # casting with 'same_kind' allows casting to data types of the same kind array5 = array1.astype(np.int32, casting='same_kin
🌐
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 - For arithmetic operations like +, -, *, //, and **, operations involving only integers return int, while those involving at least one floating-point number return float. This is equivalent to the implicit type conversion of the NumPy array ndarray. NumPy: Cast ndarray to a specific dtype with astype()
🌐
Sentry
sentry.io › sentry answers › python › change a column type in a dataframe in python pandas
Python Change Column Dtype in Pandas With astype() | Sentry
If we want to convert a column from any data type to one specific data type (e.g. integer, float, string), we should use the astype method.
🌐
Codecademy
codecademy.com › docs › python:numpy › ndarray › .astype()
Python:NumPy | ndarray | .astype() | Codecademy
July 18, 2024 - The following example shows the use of the .astype() function to convert the elements of an array from floating-point data type to integer data type: ... Machine Learning Data Scientists solve problems at scale, make predictions, find patterns, and more! They use Python, SQL, and algorithms.
🌐
Vultr Docs
docs.vultr.com › python › third party › pandas › dataframe › astype()
Python Pandas DataFrame astype() - Change Data Type
December 24, 2024 - import pandas as pd data = {'col1': [1, 2, 3], 'col2': ['4', '5', '6']} df = pd.DataFrame(data) df['col2'] = df['col2'].astype(int) print(df) ... This code converts the col2 from string type to integer type.
🌐
YouTube
youtube.com › watch
Astype Function - Convert The Datatypes || Python Pandas Tutorial - 6 - YouTube
Astype() Function - To convert the data type of a column (series) to a new data type. ['column_name'].astype(int) - Convert to Integer['column_name'].astype(...
Published: June 25, 2025
🌐
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
🌐
AskPython
askpython.com › python › built-in-methods › python-astype
Python astype() - Type Conversion of Data columns - AskPython
November 30, 2020 - Python astype() method enables us to set or convert the data type of an existing data column in a dataset or a data frame.
🌐
iO Flood
ioflood.com › blog › pandas-astype
Pandas astype() Function | Data Type Conversion Guide
June 6, 2024 - In this example, we first printed out the original DataFrame and its data types. We can see that the ‘A’ column is of type ‘object’, which is used for strings in pandas. We then used the astype() function to convert the ‘A’ column to integers, and printed out the DataFrame and its data types again.
🌐
GitHub
github.com › modin-project › modin › issues › 1678
DataFrame.astype(int) has no effect · Issue #1678 · modin-project/modin
July 1, 2020 - Python 3.8.2 · Code we can use to reproduce: import modin.pandas as pd df = pd.DataFrame(index=["row1", "row2", "row3"], columns=["col1"]) df.loc["row1"]["col1"] = 11 df.loc["row2"]["col1"] = 21 df.loc["row3"]["col1"] = 31 print(df) print(df.dtypes) df1 = df.astype(int) print(df1) print(df1.dtypes) When DataFrame is first created without any contents, all of its columns are marked as object type. Even when it is filled with integers it doesn't change anything.
Author: modin-project
🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
NumPy: astype() to change dtype of an array | note.nkmk.me
February 4, 2024 - As mentioned above, dtype can also be specified as a type name string, type code string, or Python type. a_int = a.astype('int32') print(a_int) print(a_int.dtype) # [1 2 3] # int32 a_uint = a.astype('u8') print(a_uint) print(a_uint.dtype) # [1 2 3] # uint64 a_float = a.astype(float) print(a_float) print(a_float.dtype) # [1. 2. 3.] # float64 · source: numpy_astype.py · Converting from floating-point numbers (float) to integers (int) truncates the decimal part (rounding towards 0).