根据列值而不是索引值从 pandas 数据框中排除行 [英] excluding rows from a pandas dataframe based on column value and not index value
本文介绍了根据列值而不是索引值从 pandas 数据框中排除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我查看了数据框列中的唯一值-我拥有的熊猫.而且我不想在其中一列中包含一些名称,如何在不使用索引值表示法的情况下从数据框中删除这些行,而是通过说出如果row value ="this"然后删除
I looked at the unique values in a column of a dataframe - pandas that I have. And there are some names in one of the columns that I do not want to include, how do I remove those rows from the dataframe, without using index value notation, but by saying if row value = "this" then remove
喜欢...
new = df.copy
df['some column'].drop_values('this','that','other')
推荐答案
请参见 使用isin
进行索引(也
See indexing with isin
(also, boolean indexing):
mask = df['some column'].isin(['this', 'that', 'other'])
df[~mask]
这篇关于根据列值而不是索引值从 pandas 数据框中排除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文