Pandas is a special tool which allows us to perform complex manipulations of data effectively and efficiently. Inside pandas, we mostly deal with a dataset in the form of DataFrame. DataFrames are 2-dimensional data structure in pandas. DataFrames consists of rows, columns and the data. The data inside the rows and columns can be of any type like int, float, string etc.
In this article, we are going to learn how to convert floats to ints in pandas DataFrame? For this purpose, we are going to use pandas.DataFrame.astype() method.
pandas.DataFrame.astype()
This method is used for type casting. It cast an object to a specified dtype, it is very easy to understand when it comes to cast the data type of a particular column.
Syntax:
DataFrame.astype(
dtype,
copy=True,
errors='raise'
)
# or
DataFrame.astype(dtype='')
To work with pandas, we need to import pandas package first, below is the syntax:
import pandas as pd
Let us understand with the help of an example:
Output:

need an explanation for this answer? contact us directly to get an explanation for this answer