Conditionally update Data Frame column
<p>I'm trying to update a column from a value of 0 to a value of 1 if certain conditions are true. Here is my code:</p>

<pre><code>df_['win'] = 0
df_.loc[df_['predicted_spread'] &gt; df_['vegas_spread'] and df_['actual_spread'] &gt; df_['vegas_spread'], 'win'] = 1
</code></pre>

<p>This is the error I'm getting:</p>

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

<p>Does anybody have any ideas of what's going on here?</p>

<p>When doing boolean indexing you need to use the logical operator for <code>and</code> which is <code>&amp;</code>. See the doc <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow">here</a> for more info</p>

<pre><code>df['win'] = 0
cond_1 = df['predicted_spread'] &gt; df['vegas_spread']
cond_2 = df['actual_spread'] &gt; df['vegas_spread']
df.loc[cond_1 &amp; cond_2, 'win'] = 1
</code></pre>

<p>Basically just your answer with <code>&amp;</code> instead of <code>and</code>. I just rewrote it to make it a little clearer.</p>

python pandas