Skip to main contentSkip to solution

What is correct way to display the data types of each column in a DataFrame?

Solution

✅ Correct Option: 2

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).

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question