pivot_operator

Pivots a dataframe

class tasrif.processing_pipeline.pandas.pivot_operator.PivotOperator(**kwargs)

Pivots a dataframe.

Examples

>>> import pandas as pd
>>> from tasrif.processing_pipeline.pandas import PivotOperator
>>> df = pd.DataFrame([
>>>     [1, "2020-05-01 00:00:00", 1],
>>>     [1, "2020-05-01 01:00:00", 1],
>>>     [1, "2020-05-01 03:00:00", 2],
>>>     [2, "2020-05-02 00:00:00", 1],
>>>     [2, "2020-05-02 01:00:00", 1]],
>>>     columns=['logId', 'timestamp', 'sleep_level'])
>>>
>>> df['timestamp'] = pd.to_datetime(df['timestamp'])
>>> op = PivotOperator(index='timestamp', columns='logId', values='sleep_level')
>>> op.process(df)[0]
logId   1   2
timestamp
2020-05-01 00:00:00   1.0   NaN
2020-05-01 01:00:00   1.0   NaN
2020-05-01 03:00:00   2.0   NaN
2020-05-02 00:00:00   NaN   1.0
2020-05-02 01:00:00   NaN   1.0
__init__(**kwargs)

Creates a new instance of PivotOperator

Parameters

**kwargs – Arguments to pandas pivot function