python time lags holidays
<p>In pandas, I have two data frames. One containing the Holidays of a particular country from <a href="http://www.timeanddate.com/holidays/austria" rel="nofollow">http://www.timeanddate.com/holidays/austria</a> and another one containing a date column. I want to calculate the <code>#days</code> after a holiday.</p>

<pre><code>def compute_date_diff(x, y):
    difference = y - x
    differenceAsNumber = (difference/ np.timedelta64(1, 'D'))
    return differenceAsNumber.astype(int)

for index, row in holidays.iterrows():
    secondDF[row['name']+ '_daysAfter'] = secondDF.dateColumn.apply(compute_date_diff, args=(row.day,))
</code></pre>

<p>However, this</p>

<ul>
<li>calculates the wrong difference e.g. <code>&gt;</code> than a year in case <code>holidays</code> contains data for more than a year.</li>
<li>is pretty slow.</li>
</ul>

<p>How could I <strong>fix the flaw</strong> and <strong>increase performance</strong>? Is there a parallel apply? Or what about <a href="http://pandas.pydata.org/pandas-docs/stable/timeseries.html#holidays-holiday-calendars" rel="nofollow">http://pandas.pydata.org/pandas-docs/stable/timeseries.html#holidays-holiday-calendars</a>
As I am new to pandas I am unsure how to obtain the current date/index of the date object whilst iterating through in apply. As far as I know I cannot loop the other way round e.g. over all my rows in <code>secondDF</code> as it was impossible for me to generate feature columns whilst iterating via <code>apply</code></p>

<p>To do this, join both data frames using a common column and then try this code</p>

<pre><code>import pandas
import numpy as np
df = pandas.DataFrame(columns=['to','fr','ans'])
df.to = [pandas.Timestamp('2014-01-24'), pandas.Timestamp('2014-01-27'), pandas.Timestamp('2014-01-23')]
df.fr = [pandas.Timestamp('2014-01-26'), pandas.Timestamp('2014-01-27'), pandas.Timestamp('2014-01-24')]
df['ans']=(df.fr-df.to) /np.timedelta64(1, 'D')
print df
</code></pre>

<p>output </p>

<pre><code>          to         fr  ans
0 2014-01-24 2014-01-26  2.0
1 2014-01-27 2014-01-27  0.0
2 2014-01-23 2014-01-24  1.0
</code></pre>

python date pandas difference