TypeError:访问数据框的dtypes时,“系列"对象不可调用 [英] TypeError: 'Series' object is not callable when accessing dtypes of a dataframe
问题描述
什么鬼? 我没有将关键字更改为读取目录中的文本文件.
What the hell? I didn't change the keyword to reading the text file I have on my directory.
但是我无法通过我所知道的两种方法来检查每列的dtype.
Yet I can't check the dtype of each columns by the two methods that I know of.
如果我使用.dtypes
,它将返回TypeError(不可调用):
If I use .dtypes
it would return TypeError that Series is not callable:
在这里它返回AttributeError ..现在声称我读取的是数据帧:
Here it returns AttributeError.. now claiming what I read is dataframe:
有什么想法吗?
推荐答案
这里没有歧义. file
是一个数据框,dtypes
是一个属性.
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
当您访问dtypes
时,将返回一个系列:
When you access dtypes
, a Series is returned:
type(df.dtypes)
pandas.core.series.Series
调用df.dtypes()
时,实际上是在做无效的series = df.dtype; series()
,因为series
是对象(不是函数或定义了__call__
的对象).
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).
在第二种情况下,dtype
甚至不是df
的有效属性/方法,因此引发了AttributeError
.
In the second case, dtype
isn't even a valid attribute/method of df
, and so an AttributeError
is raised.
TLDR;第一个错误出现在dtype
系列上,第二个错误出现在原始数据帧df
上.
TLDR; The first error is raised on the dtype
series, the second is raised on the original dataframe df
.
这篇关于TypeError:访问数据框的dtypes时,“系列"对象不可调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!