Kenny1234
Kenny1234

Reputation: 23

How to remove rows that contains a repeating number pandas python

I have a dataframe like:

'a' 'b' 'c' 'd'
 0   1   2   3
 3   3   4   5
 9   8   8   8

and I want to remove rows that have a number that repeats more than once. So the answer is :

'a' 'b' 'c' 'd'
 0   1   2   3

Thanks.

Upvotes: 2

Views: 48

Answers (1)

jezrael
jezrael

Reputation: 863731

Use DataFrame.nunique with compare length of columns ad filter by boolean indexing:

df = df[df.nunique(axis=1) == len(df.columns)]
print (df)
   'a'  'b'  'c'  'd'
0    0    1    2    3

Upvotes: 5

Related Questions