TypeError: 'Series' object is not callable when accessing dtypes of a dataframe

Question:

duplicate. should be removed..

Asked By: dia

||

Answers:

There’s no ambiguity here. file is a dataframe, and dtypes is an attribute.

df
        productView  order
userId                    
A               4.5    5.0
B               1.5    2.5
C               4.0    2.0
D               2.0    3.0

df.dtypes
productView    float64
order          float64
dtype: object

When you access dtypes, a Series is returned:

type(df.dtypes)
pandas.core.series.Series

When you call df.dtypes(), you are effectively doing series = df.dtype; series() which is invalid, since series is an object (not a function, or an object with __call__ defined).

In the second case, dtype isn’t even a valid attribute/method of df, and so an AttributeError is raised.

TLDR; The first error is raised on the dtype series, the second is raised on the original dataframe df.

Answered By: cs95
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.