本文介绍了在 pandas df/series上使用.groupby()后如何预览行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用df.groupby(df.index.month)
后,我想预览我的DataFrame
,但是.head
删除了组格式,并且df['col'][:3]
返回以下错误:
After using df.groupby(df.index.month)
I would like to preview my DataFrame
unfortunately .head
removes the group formatting and df['col'][:3]
returns the following error:
---------------------------------------------------------------------------
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:
有什么办法解决这个问题吗?
Is there any way around this?
更新:检查完组后,我想根据@chrisb的帖子test.get_group(5)['col'].median()
Update: After checking the groups I wanted to do some which operations on the data which I did based on @chrisb's post test.get_group(5)['col'].median()
推荐答案
是这样的吗? gb
是GroupBy对象.这将打印出前3组中的前5行.
Something like this? gb
is the GroupBy object. This prints the first 5 rows from the first 3 groups.
In [230]: gb = df.groupby(df.index.month)
In [231]: for k in gb.groups.keys()[:3]:
...: print gb.get_group(k)[:5]
这篇关于在 pandas df/series上使用.groupby()后如何预览行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!