使用任意数量的条件过滤Pandas Dataframe(Filter Pandas Dataframe using an arbitrary number of conditions)
我很熟悉使用Pandas进行基本过滤和查询。 例如,如果我有一个名为
df
的数据帧,我可以做df[df['field1'] < 2]
或df[df['field2'] < 3]
。 我也可以将多个标准链接在一起,例如:
df[(df['field1'] < 3) & (df['field2'] < 2)]
。如果我事先不知道需要使用多少条件怎么办? 有没有办法将任意数量的这些操作“链接”在一起? 我想传递一个过滤器列表,如
[('field1', 3), ('field2', 2), ('field3', 4)]
,这将导致这三个条件链接在一起。谢谢!
I am comfortable with basic filtering and querying using Pandas. For example, if I have a dataframe called
df
I can dodf[df['field1'] < 2]
ordf[df['field2'] < 3]
. I can also chain multiple criteria together, for example:
df[(df['field1'] < 3) & (df['field2'] < 2)]
.What if I don't know in advance how many criteria I will need to use? Is there a way to "chain" an arbitrary number of these operations together? I would like to pass a list of filters such as
[('field1', 3), ('field2', 2), ('field3', 4)]
which would result in the chaining of these 3 conditions together.Thanks!
原文:https://stackoverflow.com/questions/47147414
最满意答案
你需要通过Javascript做任何理由吗? 您只能使用CSS执行此操作。
HTML:
<input type="checkbox" /> <label>Check Me!</label>
CSS:
input[type=checkbox] + label { color: black; } input[type=checkbox]:checked + label { background: red; }
Any reason you need to do this via Javascript? You can do this using CSS only.
HTML:
<input type="checkbox" /> <label>Check Me!</label>
CSS:
input[type=checkbox] + label { color: black; } input[type=checkbox]:checked + label { background: red; }
相关问答
更多-
你需要通过Javascript做任何理由吗? 您只能使用CSS执行此操作。 HTML: CSS: input[type=checkbox] + label { color: black; } input[type=checkbox]:checked + label { background: red; } 在这里演示 Any reason you need to do this via ...
-
试试这个: $('li span[id^="select"]').click(function(){ $(this).css('background-color',"#ccc") }) 它的作用是,点击具有以“select”开头的id的li内的span会改变背景颜色。 Try this one : $('li span[id^="select"]').click(function(){ $(this).css('background-color',"#ccc") }) what it doe ...
-
我认为这符合你的要求。 1.创建一个函数来生成随机颜色 2.为每个td调用该函数并作为背景色添加 //Table de multiplication de 1 a 12 function tablede2(n){ var ch = "