Python Pandas ValueError on simple query
<p>The following line causes a ValueError (Pandas 17.1), and I'm trying to understand why.</p>

<pre><code>x = (matchdf['ANPR Matched_x'] == 1)
</code></pre>

<p>ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().</p>

<p>I'm trying to use it for following conditional assignment:</p>

<pre><code>matchdf.loc[x, 'FullMatch'] = 1
</code></pre>

<p>But I can't get past the previous issue.</p>

<p>I'm sure I've done this kind of thing dozens of times before, and I can't see why it should matter what is in the dataframe, but perhaps it does? or more likely, I'm probably making a silly mistake I just can't see!</p>

<p>Thanks for any help.</p>

<p>EDIT: For more context here's some preceding code:</p>

<pre><code>inpairs = []
for m in inmatchedpairs:
    # more code
    p = {'Type In': mtype ,'Best In Time': besttime, 'Best G In Time': bestgtime,
         'Reg In': reg, 'ANPR Matched': anprmatch, 'ANPR Match Key': anprmatchkey}
    inpairs.append(p)

outpairs = []
for m in outmatchedpairs:
    # more code
    p = {'Type Out': mtype ,'Best Out Time': besttime, 'Best G Out Time': bestgtime,
         'Reg Out': reg, 'ANPR Matched': anprmatch, 'ANPR Match Key': anprmatchkey}
    outpairs.append(p)

indf = pd.DataFrame(inpairs)
outdf = pd.DataFrame(outpairs)
matchdf = pd.merge(indf, outdf, how='outer', on='ANPR Match Key')
matchdf['FullMatch'] = 0

x = (matchdf['ANPR Matched_x'] == 0)
</code></pre>

<p>I get the error on the last line.</p>

<p>If you have this kind of error, first check your dataframe contains what you think it does.</p>

<p>I was stupidly ending up with some Series objects being added to one of the columns which should have contained ints!</p>

python pandas numpy