MCPcopy
hub / github.com/pandas-dev/pandas / groupby

Method groupby

pandas/core/indexes/base.py:6554–6578  ·  view source on GitHub ↗

Group the index labels by a given array of values. Parameters ---------- values : array Values used to determine the groups. Returns ------- dict {group name -> group labels}

(self, values)

Source from the content-addressed store, hash-verified

6552
6553 @final
6554 def groupby(self, values) -> PrettyDict[Hashable, Index]:
6555 """
6556 Group the index labels by a given array of values.
6557
6558 Parameters
6559 ----------
6560 values : array
6561 Values used to determine the groups.
6562
6563 Returns
6564 -------
6565 dict
6566 {group name -> group labels}
6567 """
6568 # TODO: if we are a MultiIndex, we can do better
6569 # that converting to tuples
6570 if isinstance(values, ABCMultiIndex):
6571 values = values._values
6572 values = Categorical(values)
6573 result = values._reverse_indexer()
6574
6575 # map to the label
6576 result = {k: self.take(v) for k, v in result.items()}
6577
6578 return PrettyDict(result)
6579
6580 def map(self, mapper, na_action: Literal["ignore"] | None = None):
6581 """

Callers 13

test_groupbyMethod · 0.95
to_iter_dictMethod · 0.45
_form_blocksFunction · 0.45
_consolidateFunction · 0.45
__internal_pivot_tableFunction · 0.45
_groupby_and_mergeFunction · 0.45
_value_countsMethod · 0.45
_nthMethod · 0.45

Calls 5

_reverse_indexerMethod · 0.95
takeMethod · 0.95
CategoricalClass · 0.90
PrettyDictClass · 0.90
itemsMethod · 0.45

Tested by 1

test_groupbyMethod · 0.76