2024-04-20 07:30:27 发布
网友
怎么回事? 我没有将关键字改为读取目录中的文本文件。
但是我不能用我知道的两种方法检查每一列的数据类型。
如果我使用.dtypes,它将返回不能调用序列的TypeError:
.dtypes
在这里它返回attributerror。。现在声称我读到的是数据帧:
有什么想法吗?
这里没有歧义。file是一个数据帧,而dtypes是一个属性。
file
dtypes
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时,将返回一个序列:
type(df.dtypes) pandas.core.series.Series
当您调用df.dtypes()时,实际上是在执行series = df.dtype; series()这是无效的,因为series是一个对象(不是一个函数,或者定义了__call__的对象)。
df.dtypes()
series = df.dtype; series()
series
__call__
在第二种情况下,dtype甚至不是df的有效属性/方法,因此引发了AttributeError。
dtype
df
AttributeError
TLDR;第一个错误出现在dtype系列上,第二个错误出现在原始数据帧df上。
这里没有歧义。
file
是一个数据帧,而dtypes
是一个属性。当您访问
dtypes
时,将返回一个序列:当您调用
df.dtypes()
时,实际上是在执行series = df.dtype; series()
这是无效的,因为series
是一个对象(不是一个函数,或者定义了__call__
的对象)。在第二种情况下,
dtype
甚至不是df
的有效属性/方法,因此引发了AttributeError
。TLDR;第一个错误出现在
dtype
系列上,第二个错误出现在原始数据帧df
上。相关问题 更多 >
编程相关推荐