VertexFrame timeseries_from_observations¶
-
timeseries_from_observations
(self, date_time_index, timestamp_column, key_column, value_column)¶ Returns a frame that has the observations formatted as a time series.
Parameters: date_time_index : list
DateTimeIndex to conform all series to.
timestamp_column : unicode
The name of the column telling when the observation occurred.
key_column : unicode
The name of the column that contains which string key the observation belongs to.
value_column : unicode
The name of the column that contains the observed value.
Returns: : Frame
- Uses the specified timestamp, key, and value columns and the date/time
- index provided to format the observations as a time series. The time series frame will have columns for the key and a vector of the observed values that correspond to the date/time index.
Examples
In this example, we will use a frame of observations of resting heart rate for three individuals over three days. The data is accessed from Frame object called my_frame:
>>> my_frame.inspect( my_frame.row_count ) [#] name date resting_heart_rate ========================================================== [0] Edward 2016-01-01T12:00:00.000Z 62.0 [1] Stanley 2016-01-01T12:00:00.000Z 57.0 [2] Edward 2016-01-02T12:00:00.000Z 63.0 [3] Sarah 2016-01-02T12:00:00.000Z 64.0 [4] Stanley 2016-01-02T12:00:00.000Z 57.0 [5] Edward 2016-01-03T12:00:00.000Z 62.0 [6] Sarah 2016-01-03T12:00:00.000Z 64.0 [7] Stanley 2016-01-03T12:00:00.000Z 56.0
We then need to create an array that contains the date/time index, which will be used when creating the time series. Since our data is for three days, our date/time index will just contain those three dates:
>>> datetimeindex = ["2016-01-01T12:00:00.000Z","2016-01-02T12:00:00.000Z","2016-01-03T12:00:00.000Z"]
Then we can create our time series frame by specifying our date/time index along with the name of our timestamp column (in this example, it’s
“date”), key column (in this example, it’s “name”), and value column (inthis example, it’s “resting_heart_rate”).
>>> ts = my_frame.timeseries_from_observations(datetimeindex, "date", "name", "resting_heart_rate") [===Job Progress===]
Take a look at the resulting time series frame schema and contents:
>>> ts.schema [(u'name', <type 'unicode'>), (u'resting_heart_rate', vector(3))] >>> ts.inspect() [#] name resting_heart_rate ================================ [0] Stanley [57.0, 57.0, 56.0] [1] Edward [62.0, 63.0, 62.0] [2] Sarah [None, 64.0, 64.0]