How to use python to fill in dates and values so that every day has the same number of entries?
<p>I have a data set that looks like the table below. Every day has time stamps with 15 minutes interval, so there should be 15*24 = 96 entries per day. It is important that each day has the same number of values, because the np.corrceof() function I will use later to find the correlation of each day requires this. </p>

<pre><code>date               value
5/1/2015 0:00:00    23
5/1/2015 0:15:00    22
5/1/2015 0:30:00    50
......
5/1/2015 23:30:00   60
5/1/2015 23:45:00   27
</code></pre>

<p>However, the problem right now is that some days are missing values. For example, 5/2/2016 below only have two entries. </p>

<pre><code>5/2/2015 0:00:00    60
5/2/2015 0:15:00    45
5/3/2015 0:00:00    60  
......
</code></pre>

<p>What I hope to do is to complete the 5/2/2015 time series by adding 94 extra rows (0:30:00, 0:45:00, ...23:45:00)  and use 45 (the last value in 5/2/2015) as the duplicate for all the "fake data" created for the rest of this day. I also hope the script can do the same for the other days that are missing values.</p>

<p>I heard about the python interpolation function (scipy.interpolate) but it does not seem to work here? </p>

<p>Apologize for not showing any coding examples as I have no clues how to do it in a pythonian way. If you could give me a small example of how to solve this problem or just point me to the right function that would be great. Thank you for your help in advance!</p>

<p>Here an example: </p>

<pre><code>import pandas as pd


index = pd.date_range('5/1/2015', periods=12, freq='15T')
series = pd.Series(range(12), index=index)


series = series.drop(series[2:5].index)

print(series)

print(series.resample('15T').pad())
print(series.resample('15T').bfill())
print(series.resample('15T').interpolate(method='linear'))
</code></pre>

<p>Either use <code>pad</code>  (use last value for missing ones) <code>bfill</code> (backfill) or <code>interpolate</code> with an appropriate interpolation method to fill missing values.</p>

python