TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Five methods for Filtering data with multiple conditions in Python

64 点作者 min2bro超过 5 年前

9 条评论

danpalmer超过 5 年前
Title should probably clarify that this is with Pandas, that&#x27;s much more specific and less generally useful than &quot;in Python&quot;.<p>Original title: &quot;Pandas dataframe filter with Multiple conditions&quot;
RobinL超过 5 年前
To help readability I tend to do something like this:<p>f1 = (df[&quot;col1&quot;] == condition1)<p>f2 = (df[&quot;col2&quot;] == condition2)<p>df[f1 &amp; f2]<p>This is equivalent to the &#x27;pandas boolean indexing multiple conditions&#x27; method.
评论 #22111618 未加载
TrackerFF超过 5 年前
This is probably gonna be sacrilege to the Pythonians, but I often wish there was support for some SQL-like syntax when working with (pandas) data frames. It certainly would make the process a lot smoother for some tasks.
评论 #22109788 未加载
评论 #22108647 未加载
评论 #22108529 未加载
评论 #22108583 未加载
评论 #22110956 未加载
SiempreViernes超过 5 年前
This seems to be about doing filtering with Pandas, not pure python. The title should probably be changed to reflect this.
brian_herman__超过 5 年前
Yeah it looks like his code that this person uploaded isnt escaping the HTML or is being unescaped when it should be escaped.<p>df.loc[(df[&#x27;Salary_in_1000&#x27;]&gt;=100) &amp;amp; (df[&#x27;Age&#x27;]&amp;lt; 60) &amp;amp; (df[&#x27;FT_Team&#x27;].str.startswith(&#x27;S&#x27;)),[&#x27;Name&#x27;,&#x27;FT_Team&#x27;]]
lordgrenville超过 5 年前
Would have been nice to see a comparison of performance, or at least which is suggested style.
评论 #22110984 未加载
closed超过 5 年前
One thing that really surprises me: NONE of these methods work with grouped DataFrames.<p>But grouping data is extremely common in data analysis.<p>Basically, the strategy with grouped data, is taking the loc approach, and sprinkling in a bunch of additional .transform calls. :&#x2F;
评论 #22127370 未加载
data_ders超过 5 年前
I strongly prefer .query() for legibility and that it can but used in a pipe. My only problem is that often flake8 will not detect the use of a variable inside of the query string. Has anyone else come across this before?
评论 #22108566 未加载
antman超过 5 年前
Some speed comparison on a larger dataset would be interesting