Resampling timeseries with a given timedelta
<p>I am using Pandas to structure and process Data. This is my DataFrame:</p>

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

<p>I want to do a resampling of time-series data, and have, for every ID (named here "3"), all bitrate scores, from beginning to end (beginning_time / end_time). For exemple, for the first row, I want to have all seconds, from 2016-07-08 02:17:42 to 2016-07-08 02:17:55, with the same bitrate score, and the same ID of course. Something like this :</p>

<p>For example, given :</p>

<pre><code>df = pd.DataFrame(
{'Id' : ['CODI126640013.ts', 'CODI126622312.ts'],
 'beginning_time':['2016-07-08 02:17:42', '2016-07-08 02:05:35'], 
 'end_time' :['2016-07-08 02:17:55', '2016-07-08 02:26:11'],
 'bitrate': ['3750000', '3750000']})
</code></pre>

<p>which gives :</p>

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

<p>And I want to have for the first row :</p>

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

<p>Same thing for the secend row..
So the objectif is to resample the deltaTime between the beginning and the end times, the bitrate score must be the same of course.</p>

<p>I'm trying this code:</p>

<pre><code>df['new_beginning_time'] = pd.to_datetime(df['beginning_time'])
df.set_index('new_beginning_time').groupby('Id', group_keys=False).apply(lambda df: df.resample('S').ffill()).reset_index()
</code></pre>

<p>But in this context, it didn't work ! Any ideas ? Thank you very much !</p>

<p>This should do the trick</p>

<pre><code>all = []
for row in df.itertuples():
    time_range = pd.date_range(row.beginning_time, row.end_time, freq='1S')
    all += (zip(time_range, [row.Id]*len(time_range), [row.bitrate]*len(time_range)))
pd.DataFrame(all)

In[209]: pd.DataFrame(all)
Out[209]: 
                       0                 1        2
0    2016-07-08 02:17:42  CODI126640013.ts  3750000
1    2016-07-08 02:17:43  CODI126640013.ts  3750000
2    2016-07-08 02:17:44  CODI126640013.ts  3750000
3    2016-07-08 02:17:45  CODI126640013.ts  3750000
4    2016-07-08 02:17:46  CODI126640013.ts  3750000
5    2016-07-08 02:17:47  CODI126640013.ts  3750000
6    2016-07-08 02:17:48  CODI126640013.ts  3750000
7    2016-07-08 02:17:49  CODI126640013.ts  3750000
</code></pre>

<p>edit: I am using python 2.7, python 3 as a different zip() </p>

python datetime pandas group-by resampling