what is dtype at the last line while checking dtypes for all columns in Python Pandas dataframes

51 views Asked by At

What is the dtype at the last line here in the output, i am confused -

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

Here i am only asking about the last line which is 'dtype: object'. I am not asking why it is not str, my question is what is this line for?

1

There are 1 answers

2
mozway On BEST ANSWER

df.dtypes returns a Series with each column name as index and the dtype as value. When pandas displays Series is also displays the overall type of the Series below it, which is what you see here (as type are objects).

This is the value of df.dtypes.dtype.

Example:

Why there is an extra line in the display

pd.Series([1, 2, 3])

0    1           # this is the Series data
1    2           #
2    3           #
dtype: int64        # this is just for display to indicate the Series type

Why the dtype is object

df = pd.DataFrame({'A': [1], 'B': [True], 'C': ['a']})

df.dtypes

A     int64
B      bool
C    object
dtype: object  # this just indicates that we have a Series of python objects