The documentation gives a similar example at the beginning using date_range
. If you have a Series
object, you can make a DatetimeIndex
starting at the appropriate time (I'm assuming 1013
was a typo for 2013
), with a frequency of one second, and of the appropriate length:
>>> x = pd.Series(np.random.randint(8,24,23892344)) # make some random data
>>> when = pd.date_range(start=pd.datetime(2013,1,1),freq='S',periods=len(x))
>>> when
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-01-01 00:00:00, ..., 2013-10-04 12:45:43]
Length: 23892344, Freq: S, Timezone: None
and then we can make a new series from the original data using this as the new index:
>>> x_with_time = pd.Series(x.values, index=when)
>>> x_with_time
2013-01-01 00:00:00 13
2013-01-01 00:00:01 14
2013-01-01 00:00:02 15
2013-01-01 00:00:03 22
2013-01-01 00:00:04 16
[...]
2013-10-04 12:45:41 21
2013-10-04 12:45:42 16
2013-10-04 12:45:43 15
Freq: S, Length: 23892344