Pandas: Generating hourly data from daily data from csv
<p>I have a CSV file which has daily data as follows:</p>

<pre><code>DateTime        Price
10/3/2016 0:00  2.84
9/30/2016 0:00  2.84
9/29/2016 0:00  2.98
9/28/2016 0:00  3.07
</code></pre>

<p>I wanted to create 24 hour price series for each day above and the hourly prices will be same as the daily price I read from the csv file.</p>

<p>I am doing the following:</p>

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

<p>However, <code>price4mCSV</code> is blank.</p>

<p>try this:</p>

<pre><code>In [125]: df.set_index('DateTime').resample('H').pad()
Out[125]:
                     Price
DateTime
2016-09-28 00:00:00   3.07
2016-09-28 01:00:00   3.07
2016-09-28 02:00:00   3.07
2016-09-28 03:00:00   3.07
2016-09-28 04:00:00   3.07
2016-09-28 05:00:00   3.07
2016-09-28 06:00:00   3.07
2016-09-28 07:00:00   3.07
2016-09-28 08:00:00   3.07
2016-09-28 09:00:00   3.07
2016-09-28 10:00:00   3.07
2016-09-28 11:00:00   3.07
2016-09-28 12:00:00   3.07
2016-09-28 13:00:00   3.07
2016-09-28 14:00:00   3.07
2016-09-28 15:00:00   3.07
2016-09-28 16:00:00   3.07
2016-09-28 17:00:00   3.07
2016-09-28 18:00:00   3.07
2016-09-28 19:00:00   3.07
2016-09-28 20:00:00   3.07
2016-09-28 21:00:00   3.07
2016-09-28 22:00:00   3.07
2016-09-28 23:00:00   3.07
2016-09-29 00:00:00   2.98
...                    ...
2016-10-02 00:00:00   2.84
2016-10-02 01:00:00   2.84
2016-10-02 02:00:00   2.84
2016-10-02 03:00:00   2.84
2016-10-02 04:00:00   2.84
2016-10-02 05:00:00   2.84
2016-10-02 06:00:00   2.84
2016-10-02 07:00:00   2.84
2016-10-02 08:00:00   2.84
2016-10-02 09:00:00   2.84
2016-10-02 10:00:00   2.84
2016-10-02 11:00:00   2.84
2016-10-02 12:00:00   2.84
2016-10-02 13:00:00   2.84
2016-10-02 14:00:00   2.84
2016-10-02 15:00:00   2.84
2016-10-02 16:00:00   2.84
2016-10-02 17:00:00   2.84
2016-10-02 18:00:00   2.84
2016-10-02 19:00:00   2.84
2016-10-02 20:00:00   2.84
2016-10-02 21:00:00   2.84
2016-10-02 22:00:00   2.84
2016-10-02 23:00:00   2.84
2016-10-03 00:00:00   2.84

[121 rows x 1 columns]
</code></pre>

<p>or this if you don't want to have <code>DateTime</code> as an index:</p>

<pre><code>df.set_index('DateTime').resample('H').pad()
</code></pre>

python pandas dataframe