Python 根据列值而不是索引值从熊猫数据框中排除行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22392786/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
excluding rows from a pandas dataframe based on column value and not index value
提问by yoshiserry
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
我查看了数据框列中的唯一值 - 我拥有的熊猫。并且我不想包含其中一列中的一些名称,如何从数据框中删除这些行,而不使用索引值表示法,而是说 if row value = "this" then remove
like...
喜欢...
new = df.copy
df['some column'].drop_values('this','that','other')
回答by behzad.nouri
See indexing with isin(also, boolean indexing):
mask = df['some column'].isin(['this', 'that', 'other'])
df[~mask]

