Fix Python – pandas how to check dtype for all columns in a dataframe?

Question

Asked By – user3768495

It seems that dtype only work for pandas.DataFrame.Series, right? Is there a function to display data types of all columns at once?

Now we will see solution for issue: pandas how to check dtype for all columns in a dataframe?


Answer

The singular form dtype is used to check the data type for a single column. And the plural form dtypes is for data frame which returns data types for all columns. Essentially:

For a single column:

dataframe.column.dtype

For all columns:

dataframe.dtypes

Example:

import pandas as pd
df = pd.DataFrame({'A': [1,2,3], 'B': [True, False, False], 'C': ['a', 'b', 'c']})

df.A.dtype
# dtype('int64')
df.B.dtype
# dtype('bool')
df.C.dtype
# dtype('O')

df.dtypes
#A     int64
#B      bool
#C    object
#dtype: object

This question is answered By – Psidom

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0