Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-plan/src/dsl/statistics.rs
8430 views
1
use super::*;
2
3
impl Expr {
4
/// Standard deviation of the values of the Series.
5
pub fn std(self, ddof: u8) -> Self {
6
AggExpr::Std(Arc::new(self), ddof).into()
7
}
8
9
/// Variance of the values of the Series.
10
pub fn var(self, ddof: u8) -> Self {
11
AggExpr::Var(Arc::new(self), ddof).into()
12
}
13
14
/// Reduce groups to minimal value.
15
pub fn min(self) -> Self {
16
AggExpr::Min {
17
input: Arc::new(self),
18
propagate_nans: false,
19
}
20
.into()
21
}
22
23
/// Reduce groups to maximum value.
24
pub fn max(self) -> Self {
25
AggExpr::Max {
26
input: Arc::new(self),
27
propagate_nans: false,
28
}
29
.into()
30
}
31
32
/// Get minimum value, ordered by another expression.
33
pub fn min_by(self, by: Self) -> Self {
34
Expr::n_ary(FunctionExpr::MinBy, vec![self, by])
35
}
36
37
/// Get maximum value, ordered by another expression.
38
pub fn max_by(self, by: Self) -> Self {
39
Expr::n_ary(FunctionExpr::MaxBy, vec![self, by])
40
}
41
42
/// Reduce groups to minimal value.
43
pub fn nan_min(self) -> Self {
44
AggExpr::Min {
45
input: Arc::new(self),
46
propagate_nans: true,
47
}
48
.into()
49
}
50
51
/// Reduce groups to maximum value.
52
pub fn nan_max(self) -> Self {
53
AggExpr::Max {
54
input: Arc::new(self),
55
propagate_nans: true,
56
}
57
.into()
58
}
59
60
/// Reduce groups to the mean value.
61
pub fn mean(self) -> Self {
62
AggExpr::Mean(Arc::new(self)).into()
63
}
64
65
/// Reduce groups to the median value.
66
pub fn median(self) -> Self {
67
AggExpr::Median(Arc::new(self)).into()
68
}
69
70
/// Reduce groups to the sum of all the values.
71
pub fn sum(self) -> Self {
72
AggExpr::Sum(Arc::new(self)).into()
73
}
74
75
/// Compute the histogram of a dataset.
76
#[cfg(feature = "hist")]
77
pub fn hist(
78
self,
79
bins: Option<Expr>,
80
bin_count: Option<usize>,
81
include_category: bool,
82
include_breakpoint: bool,
83
) -> Self {
84
let mut input = vec![self];
85
input.extend(bins);
86
87
Expr::n_ary(
88
FunctionExpr::Hist {
89
bin_count,
90
include_category,
91
include_breakpoint,
92
},
93
input,
94
)
95
}
96
}
97
98