【发布时间】:2018-04-24 06:23:02
【问题描述】:
我是一个 Python 新手,还在学习绳索
初始化 GroupBy(_GroupBy) 导致我的代码给出一个 NameError: name '_get_grouper' 未定义
class GroupBy(_GroupBy):
def _add_numeric_operations(cls):
cls.first = GroupBy(_GroupBy).nth(-1, dropna=False)
_get_grouper 在 _GroupBy 的初始化中被调用
class _GroupBy(PandasObject, SelectionMixin):
def __init__(self, obj, keys=None, axis=0, level=None,
grouper=None, exclusions=None, selection=None, as_index=True,
sort=True, group_keys=True, squeeze=False, **kwargs):
if grouper is None:
grouper, exclusions, obj = _get_grouper(obj, keys,
axis=axis,
level=level,
sort=sort,
mutated=self.mutated)
class Grouper(object):
def _get_grouper(self, obj, validate=True):
self._set_grouper(obj)
self.grouper, exclusions, self.obj = _get_grouper(self.obj, [self.key],
axis=self.axis,
level=self.level,
sort=self.sort,
validate=validate)
return self.binner, self.grouper, self.obj
如果我在 python 命令行中调用它,则第 n 个方法会起作用,但在源代码中初始化它的类会引发此错误。我错过了什么?
【问题讨论】:
-
为什么
Grouper._get_grouper应该在_GroupBy中可见?