I have a pandas
dataframe, df
.
I want to select all indices in df
that are not in a list, blacklist.
Now, I use list comprehension to create the desired labels to slice.
ix=[i for i in df.index if i not in blacklist]
df_select=df.loc[ix]
Works fine, but may be clumsy if I need to do this often.
Is there a better way to do this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…