input column based on conditional statement pandas
<p>I have two Pandas data frames and wish to insert day and week columns from DF2 values in DF1 where the dates match. e.g. for example below, day - 4 and week - 1 would be extracted from DF2 row 1 and inserted to all of the day and week columns in DF1.</p>

<p><strong>DF 1</strong></p>

<pre><code>montgomery  year   date        day     week
0.0         2016  04/01/2016
0.0         2016  04/01/2016
0.0         2016  04/01/2016
0.0         2016  04/01/2016
</code></pre>

<p><strong>DF 2</strong></p>

<pre><code>date       day  week
04/01/2016    4   1
05/01/2016    5   1
06/01/2016    6   1
</code></pre>

<p>I have looked into using the numpy conditional statements but haven't reached a solution, thanks</p>

<p>IIUC you need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_datetime.html" rel="nofollow"><code>to_datetime</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.merge.html" rel="nofollow"><code>merge</code></a>:</p>

<pre><code>#if empty columns in DF1, remove them
DF1 = DF1.drop(['day','week'], axis=1)

#convert columns to datetimes
DF1.date = pd.to_datetime(DF1.date)
DF2.date = pd.to_datetime(DF2.date)

print (pd.merge(DF1,DF2, how='left', on='date'))
   montgomery  year       date  day  week
0         0.0  2016 2016-04-01    4     1
1         0.0  2016 2016-04-01    4     1
2         0.0  2016 2016-04-01    4     1
3         0.0  2016 2016-04-01    4     1
</code></pre>

python pandas numpy dataframe