Pandas swap columns based on condition
<p>I have a pandas dataframe like the following:</p>

<pre><code>    Col1  Col2  Col3
0   A     7     NaN
1   B     16    NaN
1   B     16    15
</code></pre>

<p>What I want to do is to swap Col2 with Col3 where the value of Col3 is <code>NaN</code>. Based on other posts and answers on SO, I have this code so far:</p>

<pre><code>df[['Col2', 'Col3']] = df[['Col3', 'Col2']].where(df[['Col3']].isnull())
</code></pre>

<p>But this does not seem to be working properly and gives me the following:</p>

<pre><code>    Col1  Col2  Col3
0   A     NaN   NaN
1   B     NaN   NaN
1   B     NaN   NaN
</code></pre>

<p>Is there something that I might be missing here?</p>

<p><strong>Update:</strong> My desired output looks like:</p>

<pre><code>    Col1  Col2  Col3
0   A     NaN   7
1   B     NaN   16
1   B     16    15
</code></pre>

<p>Thanks</p>