In pandas I have a dataframe of the form:
>>> import pandas as pd >>> df = pd.DataFrame({\'ID\':[51,51,51,24,24,24,31], \'x\':[0,1,0,0,1,
df = pd.DataFrame({'ID':[51,51,51,24,24,24,31], 'x':[0,1,0,0,1,1,0]}) df.loc[df.groupby(['ID'])['x'].transform(func=sum)>=2,:] out: ID x 3 24 0 4 24 1 5 24 1