What is correct way to display the data types of each column in a DataFrame?
What is correct way to display the data types of each column in a DataFrame?
Solution
Option 2 is the intended answer. It refers to the pandas attribute that returns the data type of every column, written in pandas as df.dtypes. It gives a Series with column names as the index and their data types (int64, float64, object, etc.) as values.
In pandas the exact spelling is plural, DataFrame.dtypes. The singular dtype is used for a single column (a Series), as in df['col'].dtype.
Option 1: pandas has no DataFrame.type. Python's built-in type(df) only tells you the object is a DataFrame.
Option 3: DataFrame.index returns the row labels, not data types.
Option 4: DataFrame.shape returns the tuple (number of rows, number of columns).
Related questions:
2025: 20 May Shift 1
2025: 13 May Shift 2
2026: 23 May Shift 2
2026: 23 May Shift 1