Pandas过滤值小于10且大于1000的数据帧行[重复]

Posted

技术标签:

【中文标题】Pandas过滤值小于10且大于1000的数据帧行[重复]【英文标题】:Pandas filter rows of data frame where value is below 10 and greather then 1000 [duplicate] 【发布时间】:2021-09-30 16:16:15 【问题描述】:

我想删除 Área 低于 10 和高于 1000 的行。

所以这很完美:

x = dataset[(dataset['Área'] > 10) ]

但这不是:

x = dataset[(dataset['Área'] > 10) and (dataset['Área'] < 1000)]

请解释一下。我正在关注本教程here。

谢谢。

【问题讨论】:

x = dataset[(dataset['Área'] &gt; 10) &amp; (dataset['Área'] &lt; 1000)] 使用&amp; 而不是and 'and' (boolean) vs '&' (bitwise) - Why difference in behavior with lists vs numpy arrays?, difference between “&” and “and” in pandas, Logical operators for boolean indexing in Pandas 也许用“&”符号代替“and”。 【参考方案1】:

这是因为and 是合乎逻辑的,即。 True and False 将产生 False。你需要按位与,即。 &amp;.

试试:

x = dataset[(dataset['Área'] > 10) & (dataset['Área'] < 1000)]

【讨论】:

以上是关于Pandas过滤值小于10且大于1000的数据帧行[重复]的主要内容,如果未能解决你的问题,请参考以下文章