user10449636
user10449636

Reputation:

Pandas: the last line of `df.dtypes` is `dtype: object`, what does that mean, whose type it is?

This code constructs a simple DataFrame

df = pd.DataFrame([[0, 1], [0, 1], [0, 1]])
df.dtypes

the output is

0    int64
1    int64
dtype: object

the last line of the output is dtype: object, what does that mean, whose type it is?

Upvotes: 10

Views: 723

Answers (1)

jezrael
jezrael

Reputation: 863166

It means Series returned of df.dtypes has dtype object, because at least obne types of Series is object here <class 'numpy.dtype'>:

s1 = df.dtypes
print (s1.dtype)
object

print (type(s1))
<class 'pandas.core.series.Series'>

If want test of types each element of Series:

print (s1.apply(type))
MPG                                         <class 'numpy.dtype'>
Cylinders                                   <class 'numpy.dtype'>
Displacement                                <class 'numpy.dtype'>
Horsepower                                  <class 'numpy.dtype'>
Weight                                      <class 'numpy.dtype'>
Acceleration                                <class 'numpy.dtype'>
Year                                        <class 'numpy.dtype'>
Origin          <class 'pandas.core.dtypes.dtypes.CategoricalD...
dtype: object

If test only integer Series it return int64 and also is displayed this information under data of Series:

s = pd.Series([1,2])
print (s)
0    1
1    2
dtype: int64

print (s.dtype)
int64

Upvotes: 2

Related Questions