Iterating over columns and reassigning values - Pandas/Python
<p>Trying to use a for loop to iterate over columns and change Yes and No's to 1 and 0.</p>

<p>For some reason, I am getting an invalid type comparison error when attempting this:</p>

<p>Panda DataFrame has multiple columns, one of them being "Combined"</p>

<pre><code>for col,row in d.iteritems():
    d.loc[d[col] == 'No', col] = 0
    d.loc[d[col] == 'Yes', col] = 1
</code></pre>

<p>TypeError: invalid type comparison</p>

<p>For comparison, I can successfully perform this on a single column without issues:</p>

<pre><code>d.loc[d['Combined'] == 'No', 'Combined'] = 0
d.loc[d['Combined'] == 'Yes', 'Combined'] = 1
</code></pre>

<p>Any reason why plugging the value of col into the loc function in place of the actual column name throws an error? Does it need to be converted to a string or something before?</p>