Skip to content

Commit 2fad2f7

Browse files
committed
Added __isub__ and groupby example to docs
1 parent cd73faa commit 2fad2f7

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

doc/source/groupby.rst

+8
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ We could naturally group by either the ``A`` or ``B`` columns or both:
126126
grouped = df.groupby('A')
127127
grouped = df.groupby(['A', 'B'])
128128
129+
If we also have a MultiIndex on columns ``A`` and ``B``, we can group by all
130+
but the specified columns
131+
132+
.. ipython:: python
133+
134+
df.set_index(['A', 'B'])
135+
grouped = df.groupby(level=df.index.names - ['B'])
136+
129137
These will split the DataFrame on its index (rows). We could also split by the
130138
columns:
131139

doc/source/whatsnew/v0.20.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Check the :ref:`API Changes <whatsnew_0200.api_breaking>` and :ref:`deprecations
2626
New features
2727
~~~~~~~~~~~~
2828

29-
- Added subtraction from FrozenLists (:issue:`15475`)
29+
- Added difference from FrozenLists (:issue:`15475`)
3030

3131
- Integration with the ``feather-format``, including a new top-level ``pd.read_feather()`` and ``DataFrame.to_feather()`` method, see :ref:`here <io.feather>`.
3232
- ``.str.replace`` now accepts a callable, as replacement, which is passed to ``re.sub`` (:issue:`15055`)

pandas/indexes/frozen.py

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def __sub__(self, other):
3636
temp = [x for x in self if x not in other]
3737
return self.__class__(temp)
3838

39+
__isub__ = __sub__
40+
3941
# Python 2 compat
4042
def __getslice__(self, i, j):
4143
return self.__class__(super(FrozenList, self).__getslice__(i, j))

pandas/tests/indexes/test_frozen.py

+7
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ def test_inplace(self):
4040
# other shouldn't be mutated
4141
self.check_result(r, self.lst)
4242

43+
def test_inplace_sub(self):
44+
q = r = self.container
45+
q -= [5]
46+
self.check_result(q, self.container - [5])
47+
# other shouldn't be mutated
48+
self.check_result(r, self.lst)
49+
4350

4451
class TestFrozenNDArray(CheckImmutable, CheckStringMixin, tm.TestCase):
4552
mutable_methods = ('put', 'itemset', 'fill')

0 commit comments

Comments
 (0)