使用df.groupby(df.index.month)
后,我想预览我的DataFrame
,.head
删除群组格式,df['col'][:3]
会返回以下错误:
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
<ipython-input-154-6783abceafb8> in <module>()
1 test= sve_DOC
2 test = test.groupby(test.index.month)
----> 3 print test['DOC_mg/L'][:3]
C:\Users\AppData\Local\Enthought\Canopy32\User\lib\site-packages\pandas\core\groupby.pyc in __getitem__(self, key)
487
488 def __getitem__(self, key):
--> 489 raise NotImplementedError
490
491 def _make_wrapper(self, name):
NotImplementedError:
有什么方法吗?
更新:在检查组后,我想根据@ chrisb的帖子test.get_group(5)['col'].median()
答案 0 :(得分:2)
这样的东西? gb
是GroupBy对象。这将打印前3组中的前5行。
In [230]: gb = df.groupby(df.index.month)
In [231]: for k in gb.groups.keys()[:3]:
...: print gb.get_group(k)[:5]
答案 1 :(得分:1)
你可以循环测试
test = df.groupby("columnTitle")
for each in test:
print each[0] #columnTitle value
print each[1] #corresponding df equivalent of df[df['columnTitle']==each[0]]