I have a dataframe df
, of the following form:
df = pd.DataFrame({'C1': {'R1': 'yes','R2': 'no','R3': 'no','R4': 'no','R5': 'no','R6': float("nan")},
'C2': {'R1': 'on','R2': 'on','R3': 'no','R4': 'yes','R5': 'no','R6': float("nan")},
'C3': {'R1': 'no', 'R2': 'no', 'R3': 'no', 'R4': 'no', 'R5': 'no', 'R6': float("nan")},
'C4': {'R1': 'no', 'R2': 'no', 'R3': 'no', 'R4': 'no', 'R5': 'no', 'R6': float("nan")},
'C5': {'R1': 'yes', 'R2': 'no', 'R3': float("nan"), 'R4': float("nan"), 'R5': 'no', 'R6': float("nan")}})
Here's what the dataframe looks like if you print it in the interactive terminal:
>>> print(df)
C1 C2 C3 C4 C5
R1 yes on no no yes
R2 no on no no no
R3 no no no no NaN
R4 no yes no no NaN
R5 no no no no no
R6 NaN NaN NaN NaN NaN
I would like to delete lines that do not contain at least one "yes" or "on". So the final data frame should be:
C1 C2 C3 C4 C5
R1 yes on no no yes
R2 no on no no no
R4 no yes no no NaN
What's the quickest way, without involving for loops or anything like that?