简体   繁体   中英

Remove rows that contain more than one occurrence of a character (in any column)

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:

在此处输入图像描述

Would become:

在此处输入图像描述

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM