Replace NAT dates with data from another column Python Pandas
<p>I am facing difficulties replacing NAT dates with data from other column. I am using python pandas by the way.</p>

<p>For example</p>

<pre><code>       Column1            Column2
       02-12-2006         2006
       05-12-2005         2005
       NAT                2008
       15-02-2015         2015
       NAT                2001
</code></pre>

<p>I have the valid dates in column1 and only the years in column2, how can i impute the NAT values using the years from column 2 based on the same row.</p>

<p>My desire result will be</p>

<pre><code>       Column1            Column2
       02-12-2006         2006
       05-12-2005         2005
       2008               2008
       15-02-2015         2015
       2001               2001
</code></pre>

<pre><code>df.Column1.combine_first(df.Column2)

0    2006-02-12 00:00:00
1    2005-05-12 00:00:00
2                   2008
3    2015-02-15 00:00:00
4                   2001
Name: Column1, dtype: object
</code></pre>

<hr>

<h3>Better Answer</h3>

<pre><code>df.Column1 = np.where(df.Column1.notnull(),
                      df.Column1.dt.strftime('%Y-%m-%d'),
                      df.Column2)

df
</code></pre>

<p><a href="http://i.stack.imgur.com/ncJSb.png" rel="nofollow"><img src="http://i.stack.imgur.com/ncJSb.png" alt="enter image description here"></a></p>

python pandas