Get pandas subseries by values when each value is a ndarray
<p>I want to make a subseries by values when the Series consists of ndarrays.</p>

<p>This one works.</p>

<pre><code>sa = pd.Series([1,2,35,2],index=list('abcd'))
sa[sa==2]
</code></pre>

<p>Results</p>

<pre><code>b    2
d    2
dtype: int64
</code></pre>

<p>Why below codes does not work? What should I change?. It gives a ValueError: Lengths must match to compare</p>

<pre><code>sa2 = pd.Series([np.array(['out']), np.array(['2f-right', '2f']), np.array(['out', '2f']), np.array(['out'])], index=list('abcd'))
ar = np.array(['out'])
sa2[sa2 == ar]
</code></pre>

<p>The comparison operator doesn't understand how to compare for equality with np arrays here so you can use <code>apply</code> with a <code>lambda</code>:</p>

<pre><code>In [211]:
sa2[sa2.apply(lambda x: (x == ar).all())]

Out[211]:
a    [out]
d    [out]
dtype: object
</code></pre>

<p>So here we compare against the array and use <code>all</code> to generate a boolean mask</p>

python pandas indexing series