'Filter our rows where all the grouped elements are equal to zero

my df:

id1 id2  uid . . . 
 1  100   0
 1  101 1000
 1  101 1000
 2  102   0
 2  103   0
 3  104 1002
 3  104 1002
 3  104 1002
 3  104   0
 3  105   0
 3  106   0
 4  107   0
 4  107   0
 4  108   0
 4  108   0

I would to group by id1 and filter out id1s where all the uids are zero.

I tried the following:

df = df.groupby(by = 'id1').filter(lambda x: x['uid'].sum() > 0).reset_index(drop = True)

But the issue is that it sums up the non-zero uids and creates random uids by doing so.

Desired result:

id1 id2  uid . . . 
 1  100   0
 1  101 1000
 1  101 1000
 3  104 1002
 3  104 1002
 3  104 1002
 3  104   0
 3  105   0
 3  106   0


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source