我有一个像这样的数据帧
Label Type
Name
ppppp Base brute UnweightedBase
pbaaa Base Base
pb4a1 Très à gauche Category
pb4a2 A gauche pb4a2 Category
pb4a3 Au centre pb4a3 Category
pb4a4 A droite pb4a4 Category
如果“Type”列的值是“UnweightedBase”和“Base”,我希望从数据中删除。在
我只能用下面的代码来完成:
^{pr2}$如何修改代码以便一次删除多个值?在
我失败的尝试:
to_del = df[df['Type'] in ["UnweightedBase","Base"]].index.tolist()
df= df.drop(to_del, axis)
return df
您可以选择所需的行并将结果数据帧重新分配给
df
:我认为这比使用更直接更安全
^{pr2}$由于后者基本上与中间步骤的选择相同:
此外,
index.tolist()
将返回索引标签。如果索引具有非唯一值,则可能会删除不需要的行。在例如:
相关问题 更多 >
编程相关推荐