jq_operator¶
Operator to resample a timeseries based dataframe
-
class
tasrif.processing_pipeline.custom.jq_operator.
JqOperator
(expression)¶ Applies a jq processing expression to the input JSON data.
Examples
>>> >>> import pandas as pd >>> from tasrif.processing_pipeline.custom import JqOperator >>> df = [ >>> { >>> "date": "2020-01-01", >>> "sleep": [ >>> { >>> "sleep_data": [ >>> { >>> "level": "rem", >>> "minutes": 180 >>> }, >>> { >>> "level": "deep", >>> "minutes": 80 >>> }, >>> { >>> "level": "light", >>> "minutes": 300 >>> } >>> ] >>> } >>> ] >>> }, >>> { >>> "date": "2020-01-02", >>> "sleep": [ >>> { >>> "sleep_data": [ >>> { >>> "level": "rem", >>> "minutes": 280 >>> }, >>> { >>> "level": "deep", >>> "minutes": 60 >>> }, >>> { >>> "level": "light", >>> "minutes": 200 >>> } >>> ] >>> } >>> ] >>> } >>> ] >>> >>> op = JqOperator("map({date, sleep: .sleep[].sleep_data})") >>> op.process(df) [[{'date': '2020-01-01', 'sleep': [{'level': 'rem', 'minutes': 180}, {'level': 'deep', 'minutes': 80}, {'level': 'light', 'minutes': 300}]}, {'date': '2020-01-02', 'sleep': [{'level': 'rem', 'minutes': 280}, {'level': 'deep', 'minutes': 60}, {'level': 'light', 'minutes': 200}]}]]
-
__init__
(expression)¶ Creates a new instance of ResampleOperator
- Parameters
expression (str) – JQ expression to process the incoming JSON datasets (see https://stedolan.github.io/jq/manual/) for more details
-