How to add date and time information to time series data using python numpy or pandas -
i have trouble using date & time calculation pandas.
i think there logics calculate duration automatically beginning specific date & time. still couldn't find it.
i'd know how add date & time info 1 second duration time series data.
before: 10 12 13 .. 20 21 19 18 after: 1013-01-01 00:00:00 10 1013-01-01 00:00:01 12 1013-01-01 00:00:02 13 .. 1013-10-04 12:45:40 20 1013-10-04 12:45:41 21 1013-10-04 12:45:42 19 1013-10-04 12:45:43 18
any appreciated. thank in advance.
the documentation gives similar example @ beginning using date_range
. if have series
object, can make datetimeindex
starting @ appropriate time (i'm assuming 1013
typo 2013
), frequency of 1 second, , of appropriate length:
>>> x = pd.series(np.random.randint(8,24,23892344)) # make 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 can make new series original data using 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
Comments
Post a Comment