-2

I'm trying to remove rows that contain more than one occurrence of a determined character in any column, but I'm not finding a way of doing that using pandas dataframe. For example:

enter image description here

Would become:

enter image description here

Does anyone know a way to do this? Thank you.

João Durante
  • 273
  • 5
  • 14
  • 1
    Would you mind posting some example data as code, not as image, with the expected input and output (cf. https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples)? – fsimonjetz May 03 '22 at 19:00

2 Answers2

2

You can use:

>>> df[~df.eq('?').sum(axis=1).gt(1)]
   x  y  z
0  1  2  ?
1  3  2  1
3  2  3  1
Corralien
  • 109,409
  • 8
  • 28
  • 52
0

If you're looking for any duplicates including the numbers, you can try:

>>> df.loc[~df.T.apply(pd.Series.duplicated, keep=False).T.any(axis=1)]
   x  y  z
0  1  2  ?
1  3  2  1
3  2  3  1
not_speshal
  • 22,093
  • 2
  • 15
  • 30