btrdb.transformers

A number of tranformation and serialization functions have been developed so you can use the data in the format of your choice. These functions are provided in the btrdb.utils.transformers module but are also available directly off the the StreamSet class.

Value transformation utilities

btrdb.transformers.to_dict(streamset, agg='mean', name_callable=None)

Returns a list of OrderedDict for each time code with the appropriate stream data attached.

Parameters:
  • agg (str, default: "mean") – Specify the StatPoint field (e.g. aggregating function) to constrain dict keys. Must be one of “min”, “mean”, “max”, “count”, or “stddev”. This argument is ignored if RawPoint values are passed into the function.
  • name_callable (lambda, default: lambda s: s.collection + "/" + s.name) – Sprecify a callable that can be used to determine the series name given a Stream object.
btrdb.transformers.to_array(streamset, agg='mean')

Returns a multidimensional numpy array (similar to a list of lists) containing point classes.

Parameters:agg (str, default: "mean") – Specify the StatPoint field (e.g. aggregating function) to return for the arrays. Must be one of “min”, “mean”, “max”, “count”, or “stddev”. This argument is ignored if RawPoint values are passed into the function.
btrdb.transformers.to_series(streamset, datetime64_index=True, agg='mean', name_callable=None)

Returns a list of Pandas Series objects indexed by time

Parameters:
  • datetime64_index (bool) – Directs function to convert Series index to np.datetime64[ns] or leave as np.int64.
  • agg (str, default: "mean") – Specify the StatPoint field (e.g. aggregating function) to create the Series from. Must be one of “min”, “mean”, “max”, “count”, or “stddev”. This argument is ignored if RawPoint values are passed into the function.
  • name_callable (lambda, default: lambda s: s.collection + "/" + s.name) – Sprecify a callable that can be used to determine the series name given a Stream object.
btrdb.transformers.to_dataframe(streamset, columns=None, agg='mean', name_callable=None)

Returns a Pandas DataFrame object indexed by time and using the values of a stream for each column.

Parameters:
  • columns (sequence) – column names to use for DataFrame. Deprecated and not compatible with name_callable.
  • agg (str, default: "mean") – Specify the StatPoint field (e.g. aggregating function) to create the Series from. Must be one of “min”, “mean”, “max”, “count”, “stddev”, or “all”. This argument is ignored if not using StatPoints.
  • name_callable (lambda, default: lambda s: s.collection + "/" + s.name) – Sprecify a callable that can be used to determine the series name given a Stream object. This is not compatible with agg == “all” at this time
btrdb.transformers.to_csv(streamset, fobj, dialect=None, fieldnames=None, agg='mean', name_callable=None)

Saves stream data as a CSV file.

Parameters:
  • fobj (str or file-like object) – Path to use for saving CSV file or a file-like object to use to write to.
  • dialect (csv.Dialect) – CSV dialect object from Python csv module. See Python’s csv module for more information.
  • fieldnames (sequence) – A sequence of strings to use as fieldnames in the CSV header. See Python’s csv module for more information.
  • agg (str, default: "mean") – Specify the StatPoint field (e.g. aggregating function) to return when limiting results. Must be one of “min”, “mean”, “max”, “count”, or “stddev”. This argument is ignored if RawPoint values are passed into the function.
  • name_callable (lambda, default: lambda s: s.collection + "/" + s.name) – Sprecify a callable that can be used to determine the series name given a Stream object.