Given a data frame, I would like to keep the rows where a given column value does not match the given strings.
For instance, if the column 'En' does not match 'x1', I will keep those rows. I use the following code to do it.
df1 = df1.loc[df1['En'] != 'x1']
If instead of x1 only, there are x1and x2 need to be examined. In other words, I will only keep the rows whose 'En' column does not match either x1 or x2. What's the most efficient way to do that.
This is how I did
df1 = df1.loc[df1['En'] != 'x1']
df1 = df1.loc[df1['En'] != 'x2']
isinwith an invert~for multiple values:df[~df1['En'].isin(['x1','x2',other_values])]