Reputation: 5133
I am trying to recover in a DataFrame the rows of the groups (by TYPE) that contain more than one element.
TYPE VALEUR
M1 A
M1 B
M2 A
the result should be :
TYPE VALEUR
M1 A
M1 B
Thanks!
Upvotes: 0
Views: 1812
Reputation: 17600
You could also use ix
if you set TYPE
as the index first:
df.set_index("TYPE", inplace=True)
df.ix[df.groupby(level=0).size() > 1]
Upvotes: 1
Reputation: 93924
Have no idea for an elegant solution. Here's my stupid one:
In [149]: m = df.groupby('TYPE').size() > 1
In [151]: df[df['TYPE'].map(m)]
Out[151]:
TYPE VALEUR
0 M1 A
1 M1 B
Upvotes: 4