File tree 1 file changed +4
-3
lines changed
1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -1137,16 +1137,17 @@ should be taken instead.
1137
1137
df2.drop_duplicates([' a' ,' b' ])
1138
1138
df2.drop_duplicates([' a' ,' b' ], take_last = True )
1139
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() ``.
1140
+ An alternative way to drop duplicates on the index is ``.groupby(level=0) `` combined with ``first() `` or ``last() ``.
1142
1141
1143
1142
.. ipython :: python
1144
1143
1145
1144
df3 = df2.set_index(' b' )
1146
1145
df3
1147
- df3.reset_index().drop_duplicates(subset = ' b' , take_last = False ).set_index(' b' )
1148
1146
df3.groupby(level = 0 ).first()
1149
1147
1148
+ # a bit more verbose
1149
+ df3.reset_index().drop_duplicates(subset = ' b' , take_last = False ).set_index(' b' )
1150
+
1150
1151
.. _indexing.dictionarylike :
1151
1152
1152
1153
Dictionary-like :meth: `~pandas.DataFrame.get ` method
You can’t perform that action at this time.
0 commit comments