ktk.TimeSeries.to_dataframe#

TimeSeries.to_dataframe()[source]#

Create a DataFrame by reshaping all data to one bidimensional table.

Undimensional data is converted to a single column, and two-dimensional (or more) data are converted to multiple columns with the additional dimensions in brackets. The TimeSeries’s events and metadata such as time_info and data_info are not included in the resulting DataFrame.

Returns

DataFrame with the index as the TimeSeries’ time.

Return type

pd.DataFrame

See also

ktk.TimeSeries.from_dataframe, ktk.TimeSeries.from_array, ktk.TimeSeries.to_array

Examples

Example with unidimensional data:

>>> ts = ktk.TimeSeries(time=np.arange(3) / 10)
>>> ts = ts.add_data("test", np.array([0.0, 2.0, 3.0]))
>>> ts.to_dataframe()
     test
0.0   0.0
0.1   2.0
0.2   3.0

Example with multidimensional data:

>>> ts = ktk.TimeSeries(time=np.arange(4) / 10)
>>> ts = ts.add_data("test", np.repeat([[0.0, 2.0, 3.0]], 4, axis=0))
>>> ts.data["test"]
array([[0., 2., 3.],
       [0., 2., 3.],
       [0., 2., 3.],
       [0., 2., 3.]])
>>> ts.to_dataframe()
      test[0]  test[1]  test[2]
 0.0      0.0      2.0      3.0
 0.1      0.0      2.0      3.0
 0.2      0.0      2.0      3.0
 0.3      0.0      2.0      3.0