analyze()
Analyze a dataset using the specified method.
Usage
analyze(
data,
method="mean",
)Computes summary statistics on the input data using the chosen aggregation method. The result includes the computed value and metadata about the analysis.
Parameters
data: list-
A list of numeric values to analyze.
method: str = "mean"-
The aggregation method to use. One of
"mean","median", or"sum". Defaults to"mean".
Returns
dict-
A dictionary with keys
"value"(the computed result),"method"(the method used), and"count"(number of data points).
Raises
ValueError-
If
datais empty ormethodis not recognized. TypeError-
If
datacontains non-numeric values.
Notes
The mean is computed as the arithmetic mean. For large datasets, consider using chunked processing to avoid memory issues.
The implementation uses a simple single-pass algorithm:
\[ \bar{x} = \frac{1}{n} \sum_{i=1}^{n} x_i \]
Warnings
This function loads all data into memory. For datasets larger than available RAM, use a streaming approach instead.
References
- Knuth, D. “The Art of Computer Programming”, Vol 2.
- https://en.wikipedia.org/wiki/Arithmetic_mean
Examples
>>> analyze([1, 2, 3, 4, 5])
{'value': 3.0, 'method': 'mean', 'count': 5}>>> analyze([10, 20, 30], method="sum")
{'value': 60, 'method': 'sum', 'count': 3}See Also
- transform(): Transform data before analysis.