Pandas reading from csv file and filling missing values for datetime index
<p>I have data in a csv file which appears as:</p>

<pre><code>  DateTime       Temp
10/1/2016 0:00  20.35491156
10/1/2016 1:00  19.75320845
10/1/2016 4:00  17.62411292
10/1/2016 5:00  18.30190001
10/1/2016 6:00  19.37101638
</code></pre>

<p>I am reading this file into csv file as:</p>

<pre><code>import numpy as np
import pandas as pd
data = pd.read_csv(r'C:\Curve.csv', index_col='DateTime')
newIndex = pd.date_range(np.min(data.index), np.max(data.index),freq='1H')
data.reindex(newIndex)
</code></pre>

<p>My goal is to backfill the missing hours 2 and 3 with 19.75320845. i.e. every time there is are missing data it should do the backfill.</p>

<pre><code>import pandas as pd
data = pd.read_csv(r'Curve.csv', index_col='DateTime', parse_dates=['DateTime'])
data = data.asfreq('1H', method='ffill')
</code></pre>

<p>yields</p>

<pre><code>                          Temp
DateTime                      
2016-10-01 00:00:00  20.354912
2016-10-01 01:00:00  19.753208
2016-10-01 02:00:00  19.753208
2016-10-01 03:00:00  19.753208
2016-10-01 04:00:00  17.624113
2016-10-01 05:00:00  18.301900
2016-10-01 06:00:00  19.371016
</code></pre>

<p><code>method='ffill'</code> tells <code>asfreq</code> to "forward-fill" missing values using the
last valid (non-NaN) value.</p>

python pandas