10000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 31782f4 commit f7c7ee0Copy full SHA for f7c7ee0
doc/source/indexing.rst
@@ -1137,6 +1137,16 @@ should be taken instead.
1137
df2.drop_duplicates(['a','b'])
1138
df2.drop_duplicates(['a','b'], take_last=True)
1139
1140
+An easier way to drop duplicates on the index than to temporarily forgo it is
1141
+``groupby(level=0)`` combined with ``first()`` or ``last()``.
1142
+
1143
+.. ipython:: python
1144
1145
+ df3 = df2.set_index('b')
1146
+ df3
1147
+ df3.reset_index().drop_duplicates(subset='b', take_last=False).set_index('b')
1148
+ df3.groupby(level=0).first()
1149
1150
.. _indexing.dictionarylike:
1151
1152
Dictionary-like :meth:`~pandas.DataFrame.get` method
0 commit comments