From 09cd583a949adf5c73143c53b05898de497ba892 Mon Sep 17 00:00:00 2001 From: flying-sheep Date: Tue, 24 Mar 2015 13:47:31 +0100 Subject: [PATCH 1/2] Document how to drop duplicate indices fixes #9708 --- doc/source/indexing.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/doc/source/indexing.rst b/doc/source/indexing.rst index 5079b4fa8ad6f..eed926e34ec5b 100644 --- a/doc/source/indexing.rst +++ b/doc/source/indexing.rst @@ -1137,6 +1137,16 @@ should be taken instead. df2.drop_duplicates(['a','b']) df2.drop_duplicates(['a','b'], take_last=True) +An easier way to drup duplicates on the index than to temporarily forgo it is +``groupby(level=0)`` combined with ``first()`` or ``last()``. + +.. ipython:: python + + df3 = df2.set_index('b') + df3 + df3.reset_index().drop_duplicates(subset='b', take_last=False).set_index('b') + df3.groupby(level=0).first() + .. _indexing.dictionarylike: Dictionary-like :meth:`~pandas.DataFrame.get` method From d79e3c52e1f91eaf1ad2641c22338316be069aee Mon Sep 17 00:00:00 2001 From: flying-sheep Date: Tue, 24 Mar 2015 13:49:06 +0100 Subject: [PATCH 2/2] typo --- doc/source/indexing.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/indexing.rst b/doc/source/indexing.rst index eed926e34ec5b..1f50a9c85343c 100644 --- a/doc/source/indexing.rst +++ b/doc/source/indexing.rst @@ -1137,7 +1137,7 @@ should be taken instead. df2.drop_duplicates(['a','b']) df2.drop_duplicates(['a','b'], take_last=True) -An easier way to drup duplicates on the index than to temporarily forgo it is +An easier way to drop duplicates on the index than to temporarily forgo it is ``groupby(level=0)`` combined with ``first()`` or ``last()``. .. ipython:: python