python pandas: date/time function to compute time period
<p>I have the following working code, trying to filter in the data within 14 days of the reference date. However, I had to hard code the date:</p>

<pre><code>reference_ts = "2016-09-15 00:00:00"
df1 = df[df.my_ts &gt;= "2016-09-01 00:00:00"]
</code></pre>

<p>I am wondering is there any function that I can use to compute a certain time period from a reference time point? Something like the pseudo code below:</p>

<pre><code>df1 = df[df.my_ts &gt;= date_sub(reference_ts,14)]
</code></pre>

<p>Thanks!</p>

<p>Yes, there is.</p>

<p>You can just check <a href="https://docs.python.org/2/library/datetime.html" rel="nofollow">timedelta</a></p>

<p>It is gonna solve your problem.</p>

python datetime pandas