新手在這裏 - 我的第一次嘗試似乎沒問題,但這是我第二次使用熊貓。 在Windows 7上使用Pandas 0.12.0時,我從SQL中讀取2個數據幀 一個和groupby一樣按預期工作,所以我確定我的問題不是語法。 但另一方面,在類型(reddf)返回pandas.core.frame.DataFrame,當嘗試reddf.groupby( '任一列')我得到 - 最後幾行 -groupby - TypeError'DataFrame'對象不可調用
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
我知道groupby是可以的,並且該列存在,所以在數據框上還有一些其他的約束/條件,我只是沒有意識到或過去。 那麼可能會導致此錯誤?我該怎麼做?我應該在未來尋找什麼?
信息請
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)
,我得到的錯誤做一個reddf.groupby( 'ModelId'),尤其如此。 感謝
感謝大家, 重複的字段名稱引起了我的問題,我不能相信我沒有 最後的評論之前通知。
現在,我不明白.index輸出如何消除其他問題,你能否詳細說明一下?如果索引缺失,不應該groupby能夠正常工作,爲什麼不呢?只是尋找一個簡短的解釋,如果你指向代碼,那很好。 感謝幫助,夥計們。
感謝您的更新信息;這排除了各種可能的原因。 – DSM
你可以發佈csv來複制這個嗎? (它是否適用於reddf = reddf [:5,:5]?) –