Skip to content
Advertisement

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

As it is [Duplicate], I have raised this to be removed. Kindly do not rollback.

Advertisement

Answer

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

JavaScript

When you access dtypes, a Series is returned:

JavaScript

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.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement