cytoflow.operations.frame_stat¶
The frame_stat
module contains one class:
FrameStatisticOp
– applies a function to subsets of a data set,
and adds the resulting statistic to the Experiment
. Unlike
ChannelStatisticOp
, which operates on a single channel, this operation
operates on entire pandas.DataFrame
.
- class cytoflow.operations.frame_stat.FrameStatisticOp[source]¶
Bases:
traits.has_traits.HasStrictTraits
Apply a function to subsets of a data set, and add it as a statistic to the experiment.
The
apply
function groups the data by the variables inby
, then applies thefunction
callable to eachpandas.DataFrame
subset. The callable should take apandas.DataFrame
as its only parameter. The return type is arbitrary, but to be used with the rest ofcytoflow
it should probably be a numeric type or an iterable of numeric types.- name¶
The operation name. Becomes the first element in the
Experiment.statistics
key tuple.- Type
Str
- function¶
The function used to compute the statistic. Must take a
pandas.DataFrame
as its only argument. The return type is arbitrary, but to be used with the rest ofcytoflow
it should probably be a numeric type or an iterable of numeric types. Ifstatistic_name
is unset, the name of the function becomes the second in element in theExperiment.statistics
key tuple.- Type
Callable
- statistic_name¶
The name of the function; if present, becomes the second element in the
Experiment.statistics
key tuple. Particularly useful iffunction
is a lambda.- Type
Str
- by¶
A list of metadata attributes to aggregate the data before applying the function. For example, if the experiment has two pieces of metadata,
Time
andDox
, settingby = ["Time", "Dox"]
will applyfunction
separately to each subset of the data with a unique combination ofTime
andDox
.- Type
List(Str)
- subset¶
A Python expression sent to Experiment.query() to subset the data before computing the statistic.
- Type
Str
- fill¶
The value to use in the statistic if a slice of the data is empty.
- Type
Any (default = 0)
Examples
>>> stats_op = FrameStatisticOp(name = "ByDox", ... function = lambda x: np.mean(x["FITC-A"], ... statistic_name = "Mean", ... by = ["Dox"]) >>> ex2 = stats_op.apply(ex)