擅长:python、mysql、java
<p>根据您的评论,此代码将返回一个长度为1的pandas系列:</p>
<pre><code>x.loc[bar==foo]['variable_im_interested_in']
</code></pre>
<p>如果将此值赋给变量,则只需访问第0个元素即可获取所需的内容:</p>
<pre><code>my_value_as_series = x.loc[bar==foo]['variable_im_interested_in']
# Assumes the index to get is number 0, but from your example, it might
# be 24 instead.
plain_value = my_value_as_series[0]
# Likewise, this needs the actual index value, not necessarily 0.
also_plain_value = my_value_as_series.ix[0]
# This one works with zero, since `values` is a new ndarray.
plain_value_too = my_value_as_series.values[0]
</code></pre>
<p>您不需要将</em>分配给变量来执行此操作,因此您只需编写<code>x.loc[bar==foo]['variable_im_interested_in'][0]</code>(或其他选项的类似内容),但将越来越多的访问器和花哨的索引语法塞进单个表达式通常是一个坏主意。</p>
<p>还要注意,您可以在对<code>loc</code>的调用中直接索引感兴趣的列:</p>
<pre><code>x.loc[bar==foo, 'variable_im_interested_in'][24]
</code></pre>