Get Datatypes of Columns in DataFrame

To get datatypes of columns in DataFrame in Pandas, use pandas.DataFrame.dtypes attribute. dtypes attribute returns a pandas Series object containing data type of each column.

In this tutorial, we will learn how to get datatypes of columns in DataFrame in Pandas using DataFrame.dtypes attribute.

Syntax

The syntax to get datatypes of columns in this DataFrame is

</>
Copy
DataFrame.dtypes

Example

In the following program, we take a DataFrame, and print the datatypes of columns in this DataFrame using DataFrame.dtypes property.

Example.py

</>
Copy
import pandas as pd

df = pd.DataFrame(
    {'name': ["apple", "banana", "cherry"], 'quant': [40, 50, 60]})
print(df.dtypes)

Output

name     object
quant     int64
dtype: object

The first column 'name' is of type object, and the second column 'quant' is of type int64.

Conclusion

In this Pandas Tutorial, we learned how to get datatypes of columns in DataFrame using DataFrame.columns attribute.