Convert range to timestamp in Pandas
<p>I have a column in a pandas data frame that goes from 0 to 172800000 in steps of 10. I would like to convert into datetime stamp with a specified date, beginning at midnight of that day. </p>

<p>So, suppose, </p>

<pre><code>time = np.arange(0,172800000, 10)
</code></pre>

<p>I would like to convert this in the following format: </p>

<pre><code>YYYY-MM-DD: HH:MM:SS.XXX
</code></pre>

<p>The starting date should be <strong>2016-09-20</strong>. </p>

<p>Here's what I have done: </p>

<pre><code># Create a dummy frame as an example: 
test = pd.DataFrame()
time = np.arange(0, 172800000, 10)
test['TIME'] = time
data = np.random.randint(0, 1000, size=len(time))
test['DATA'] = data

# Convert time to datetime:
test['TIME'] = pd.to_datetime(test['TIME'], unit='ms') 
</code></pre>

<p>If I check the head of the data frame, I get the following: </p>

<pre><code>             TIME           DATA
0   1970-01-01 00:00:00.000 681
1   1970-01-01 00:00:00.010 986
2   1970-01-01 00:00:00.020 957
3   1970-01-01 00:00:00.030 422
4   1970-01-01 00:00:00.040 319
</code></pre>

<p>How do I get the year, month, and day to start on 2016, 09, 20 and not 1970?</p>

<p>This is the raison d'Ètre for <code>pandas.date_range()</code>:</p>

<pre><code>import pandas as pd

test = pd.DataFrame({'TIME': pd.date_range(start='2016-09-20',
                                           freq='10ms', periods=20)})
print(test)
</code></pre>

<p>Output:</p>

<pre class="lang-none prettyprint-override"><code>                      TIME
0  2016-09-20 00:00:00.000
1  2016-09-20 00:00:00.010
2  2016-09-20 00:00:00.020
3  2016-09-20 00:00:00.030
4  2016-09-20 00:00:00.040
5  2016-09-20 00:00:00.050
6  2016-09-20 00:00:00.060
7  2016-09-20 00:00:00.070
8  2016-09-20 00:00:00.080
9  2016-09-20 00:00:00.090
10 2016-09-20 00:00:00.100
11 2016-09-20 00:00:00.110
12 2016-09-20 00:00:00.120
13 2016-09-20 00:00:00.130
14 2016-09-20 00:00:00.140
15 2016-09-20 00:00:00.150
16 2016-09-20 00:00:00.160
17 2016-09-20 00:00:00.170
18 2016-09-20 00:00:00.180
19 2016-09-20 00:00:00.190
</code></pre>

<p>(Substitute <code>periods=20</code> for <code>periods=172800000</code>)</p>

python pandas