Reputation: 357
I have a pandas dataframe consisting of 23 series with a default sequential index (0,1,2,...) obtained by importing an ndarray.
Two of the series in the dataframe contain record time information. One series ('SECONDS') contains the number of seconds since the start of the year 1900. The other series ('NANOSECONDS') contains the number of nanoseconds into the corresponding second.
In python the conversion can be accomplished (on a single record) as:
import datetime as dt
Mydt = dt.datetime(1990,1,1,0,0,0) + dt.timedelta(seconds = 706500000)
print Mydt
Does there exist in pandas methods to perform a similar array calculation to obtain a datetime(64) date/time stamp with which I can replace the current sequential dataframe index?
Upvotes: 4
Views: 3050
Reputation: 16970
Suppose sec
is an array of integers that represents the number of seconds since 1990:
In [26]: import pandas as pd
In [27]: pd.Index(datetime(1990, 1, 1) + sec * pd.offsets.Second())
Out[27]:
<class 'pandas.tseries.index.DatetimeIndex'>
[1990-01-01 00:14:40, ..., 1990-04-26 17:26:52]
Length: 10000, Freq: None, Timezone: None
Upvotes: 4