这是我的代码
df = df[df['scorecard_version'] != '9.0']
df = df[df['scorecard_version'] != '8.0']
df = df[df['scorecard_version'] != '10.0']
df = df[df['scorecard_version'] != '11.0']
df = df[df['scorecard_version'] != '11.1']
有没有更短的选择?
答案 0 :(得分:1)
isin
使用反向布尔值掩码~
:
df[~df['scorecard_version'].isin(['9.0','8.0','10.0','11.0','11.1'])]
使用numpy.in1d
的替代解决方案:
df[~np.in1d(df['scorecard_version'].values, ['9.0','8.0','10.0','11.0','11.1'])]