diff --git a/doc/source/groupby.rst b/doc/source/groupby.rst index 8484ccd69a983..4870ce38a846a 100644 --- a/doc/source/groupby.rst +++ b/doc/source/groupby.rst @@ -126,6 +126,14 @@ We could naturally group by either the ``A`` or ``B`` columns or both: grouped = df.groupby('A') grouped = df.groupby(['A', 'B']) +If we also have a MultiIndex on columns ``A`` and ``B``, we can group by all +but the specified columns + +.. ipython:: python + + df.set_index(['A', 'B']) + grouped = df.groupby(level=df.index.names - ['B']) + These will split the DataFrame on its index (rows). We could also split by the columns: diff --git a/doc/source/whatsnew/v0.20.0.txt b/doc/source/whatsnew/v0.20.0.txt index cf61f1975f8e9..ffdcc74986f0b 100644 --- a/doc/source/whatsnew/v0.20.0.txt +++ b/doc/source/whatsnew/v0.20.0.txt @@ -26,7 +26,7 @@ Check the :ref:`API Changes ` and :ref:`deprecations New features ~~~~~~~~~~~~ -- Added subtraction from FrozenLists (:issue:`15475`) +- Added difference from FrozenLists (:issue:`15475`) - Integration with the ``feather-format``, including a new top-level ``pd.read_feather()`` and ``DataFrame.to_feather()`` method, see :ref:`here `. - ``.str.replace`` now accepts a callable, as replacement, which is passed to ``re.sub`` (:issue:`15055`) diff --git a/pandas/indexes/frozen.py b/pandas/indexes/frozen.py index d422ef31d490b..c3959643c1d36 100644 --- a/pandas/indexes/frozen.py +++ b/pandas/indexes/frozen.py @@ -36,6 +36,8 @@ def __sub__(self, other): temp = [x for x in self if x not in other] return self.__class__(temp) + __isub__ = __sub__ + # Python 2 compat def __getslice__(self, i, j): return self.__class__(super(FrozenList, self).__getslice__(i, j)) diff --git a/pandas/tests/indexes/test_frozen.py b/pandas/tests/indexes/test_frozen.py index 5c928b91de2b6..7de730debddc7 100644 --- a/pandas/tests/indexes/test_frozen.py +++ b/pandas/tests/indexes/test_frozen.py @@ -40,6 +40,13 @@ def test_inplace(self): # other shouldn't be mutated self.check_result(r, self.lst) + def test_inplace_sub(self): + q = r = self.container + q -= [5] + self.check_result(q, self.container - [5]) + # other shouldn't be mutated + self.check_result(r, self.lst) + class TestFrozenNDArray(CheckImmutable, CheckStringMixin, tm.TestCase): mutable_methods = ('put', 'itemset', 'fill')