Is There A Better Way To Find Duplicate Rows _including_ The First/last?
Consider a Pandas data frame: import pandas as pd df = pd.DataFrame({ 'a': pd.Series([1,1,1,2,3]), 'b': pd.Series(list('asdfg')) }) I want to return all of the rows with
Solution 1:
You can count
occurrences of a
and return values>1
for duplicated rows.
In [25]: df[(df.groupby('a').transform('count')>1).values]
Out[25]:
a b
0 1 a
1 1 s
2 1 d
Post a Comment for "Is There A Better Way To Find Duplicate Rows _including_ The First/last?"