擅长:python、mysql、java
<p>我能想到的最好方法是在这种情况下使用“select”。尽管它甚至在文档中说“只有在没有更直接的方法时才应该使用这种方法。”</p>
<p><a href="http://pandas.pydata.org/pandas-docs/dev/indexing.html" rel="nofollow">Indexing and selecting data</a></p>
<pre><code>In [116]: s
Out[116]:
a 0 1.724372
1 0.305923
5 1.780811
b 0 -0.556650
1 0.207783
4 -0.177901
50 0.289365
0 1.168115
In [117]: s.select(lambda x: x[0] == 'b' and 2 <= x[1] <= 10)
Out[117]: b 4 -0.177901
</code></pre>