groupby - TypeError'DataFrame'对象不可调用 [英] groupby - TypeError 'DataFrame' object is not callable

查看:981
本文介绍了groupby - TypeError'DataFrame'对象不可调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新手在这里 - 我的第一次尝试似乎没问题,但这是我第二次使用熊猫。
在Windows 7上使用Pandas 0.12.0时,我从SQL
读取2个数据框。其中一个与groupby一起工作,所以我确定我的问题不是语法。
但另一方面,type(reddf)返回pandas.core.frame.DataFrame,当尝试reddf.groupby('any column')时,我得到 - 最后几行 -
$ b_b

  c:\python27\lib\site-packages\pandas\core\groupby.pyc in __init __(self,index,grouper,name,级别,排序)
1197#无级别通过
1198如果不是isinstance(self.grouper,np.ndarray):
- > 1199 self.grouper = self.index.map(self.grouper)
1200 if not(hasattr(self.grouper,__ len__)and \
1201 len(self.grouper)== len (self.index)):

c:\python27\lib\site-packages\pandas\algos.pyd in pandas.algos.arrmap_int64(pandas\algos.c:62839 )()

TypeError:'DataFrame'对象不可调用 groupby 是好的,并且该列存在,所以在数据框上还有一些其他约束/条件,米只是没有意识到或吹过去。
那么可能会导致这个错误?我该怎么做?我应该在未来寻找什么?



要求的信息
$ b

  print type(reddf.index)

print repr(reddf.index)
Int64Index([0,1,2,3,4,5,6,7,8,9,10,11,12,13, 14,15,16,17,18,19],dtype = int64)

打印类型(reddf.index.map)

print repr(reddf.index.map)

以防万一
reddf给出
< class'pandas.core.frame.DataFrame'>
Int64Index:20个条目,0至19
数据列(共24列):
AssetId 20个非空值
DateAdded 20个非空值
ModelId 20非空值
UsageTypeId 20个非空值
DateAdded 20个非空值
名称20个非空值
NatureId 20个非空值
IsContainer 20非空值
SparePartNumber 8个非空值
ProductNumber 19个非空值
SupportCategoryOid 20个非空值
SerialNumber 20个非空值
IpAddress 20非空值
描述20个非空值
CustomsId 15个非空值
AssetTag 20个非空值
ParentId 5个非空值
ManagementProcessorId 7非空值
OperatingSystem 20个非空值
OsVersion 20个非空值
SystemName 20个非空值
LocationId 10个非空值
RomVersion 20个非空值
MacAddress 19非空值
dtypes:bool(1),datetime64 [ns](2),float64(3),int64(5),object(13)

,特别是出现了执行reddf.groupby('ModelId')的错误。
谢谢


感谢所有人,
重复的字段名称导致了我的问题,我无法相信我没有注意到
最后一条评论。



现在,我不明白.index输出如何消除其他问题,您能详细说明一下吗?如果索引缺失,不应该groupby能够正常工作,为什么不呢?只是寻找一个简短的解释,如果你指向代码,那很好。
感谢帮助,各位。

解决方案

是由于'DateAdded'列的重复造成的。重命名它,你很好。


newbie here - my first foray seemed ok, but this is my 2nd use of pandas. In using Pandas 0.12.0 on windows 7, I read 2 dataframes from SQL One works with groupby as expected, so I'm sure my problem isn't syntax. But on the other, where type(reddf) return pandas.core.frame.DataFrame, when try reddf.groupby( 'any column') I get - last few lines -

    c:\python27\lib\site-packages\pandas\core\groupby.pyc in __init__(self, index, grouper,     name, level, sort)
   1197             # no level passed
   1198             if not isinstance(self.grouper, np.ndarray):
-> 1199                 self.grouper = self.index.map(self.grouper)
   1200                 if not (hasattr(self.grouper,"__len__") and \
   1201                    len(self.grouper) == len(self.index)):

c:\python27\lib\site-packages\pandas\algos.pyd in pandas.algos.arrmap_int64 (pandas\algos.c:62839)()

TypeError: 'DataFrame' object is not callable

I know groupby is OK, and the column exists, so there's some other constraint / condition on the dataframe that I'm just not aware of or blew past. So what could cause this error? And what should I do? What should I look for in the future?

info requested

print type(reddf.index)
<class 'pandas.core.index.Int64Index'>

print repr(reddf.index) 
Int64Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], dtype=int64)

print type(reddf.index.map)
<type 'instancemethod'>

print repr(reddf.index.map)
<bound method Int64Index.map of Int64Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], dtype=int64)>

Just in case
reddf gives
<class 'pandas.core.frame.DataFrame'>
Int64Index: 20 entries, 0 to 19
Data columns (total 24 columns):
AssetId                  20  non-null values
DateAdded                20  non-null values
ModelId                  20  non-null values
UsageTypeId              20  non-null values
DateAdded                20  non-null values
Name                     20  non-null values
NatureId                 20  non-null values
IsContainer              20  non-null values
SparePartNumber          8  non-null values
ProductNumber            19  non-null values
SupportCategoryOid       20  non-null values
SerialNumber             20  non-null values
IpAddress                20  non-null values
Description              20  non-null values
CustomsId                15  non-null values
AssetTag                 20  non-null values
ParentId                 5  non-null values
ManagementProcessorId    7  non-null values
OperatingSystem          20  non-null values
OsVersion                20  non-null values
SystemName               20  non-null values
LocationId               10  non-null values
RomVersion               20  non-null values
MacAddress               19  non-null values
dtypes: bool(1), datetime64[ns](2), float64(3), int64(5), object(13)

and I get the error doing a reddf.groupby('ModelId'), in particular. thanks

Thanks to everyone, The duplicate field name caused me the issue, I can't believe I did not notice before the last comment.

Now, I don't understand how the .index output eliminated other problems, could you elaborate? What if the index were missing, should not groupby have been able to function properly, why not? Just looking for a short explanation and if you point to code, that's fine. appreciate the help, guys.

解决方案

is caused by the duplication of 'DateAdded' column. Rename it and you are good to go.

这篇关于groupby - TypeError'DataFrame'对象不可调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆