Transformational
polars_ta.wq.transformational
Functions:
| Name | Description |
|---|---|
bool_ |
int转成bool |
clamp |
Limits input value between lower and upper bound in inverse = false mode (which is default). Alternatively, when inverse = true, values between bounds are replaced with mask, while values outside bounds are left as is. |
cut |
分箱 |
fill_nan |
填充 |
fill_null |
填充 |
float_ |
int转成float |
int_ |
bool转int |
left_tail |
NaN everything greater than maximum, maximum should be constant. |
lit_ |
将常量封装成lit |
logit |
对数几率,拉伸中间部分 |
nop |
空操作 |
purify |
Clear infinities (+inf, -inf) by replacing with null. |
right_tail |
NaN everything less than minimum, minimum should be constant. |
sigmoid |
sigmoid激活函数 |
tail |
If (x > lower AND x < upper) return newval, else return x. Lower, upper, newval should be constants. |
bool_(a: Expr) -> Expr
int转成bool
clamp(x: Expr, lower: float = 0, upper: float = 0, inverse: bool = False, mask: float = None) -> Expr
Limits input value between lower and upper bound in inverse = false mode (which is default). Alternatively, when inverse = true, values between bounds are replaced with mask, while values outside bounds are left as is.
Examples:
df = pl.DataFrame({
'a': [None, 1, 2, 3, 4, 5, 6],
}).with_columns(
out1=clamp(pl.col('a'), 2, 5, False),
out2=clamp(pl.col('a'), 2, 5, True),
)
shape: (7, 3)
┌──────┬──────┬──────┐
│ a ┆ out1 ┆ out2 │
│ --- ┆ --- ┆ --- │
│ i64 ┆ i64 ┆ i64 │
╞══════╪══════╪══════╡
│ null ┆ null ┆ null │
│ 1 ┆ 2 ┆ 1 │
│ 2 ┆ 2 ┆ null │
│ 3 ┆ 3 ┆ null │
│ 4 ┆ 4 ┆ null │
│ 5 ┆ 5 ┆ null │
│ 6 ┆ 5 ┆ 6 │
└──────┴──────┴──────┘
References
https://platform.worldquantbrain.com/learn/operators/detailed-operator-descriptions#clampx-lower-0-upper-0-inverse-false-mask
cut(x: Expr, b: float, *more_bins) -> Expr
分箱
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Expr
|
|
required |
b
|
float
|
|
required |
*more_bins
|
|
()
|
Examples:
df = pl.DataFrame({
'a': [None, 1, 1, 1, 2, 2, 3, 10],
}).with_columns(
out1=cut(pl.col('a'), 2, 5, 20),
)
shape: (8, 2)
┌──────┬──────┐
│ a ┆ out1 │
│ --- ┆ --- │
│ i64 ┆ u32 │
╞══════╪══════╡
│ null ┆ null │
│ 1 ┆ 0 │
│ 1 ┆ 0 │
│ 1 ┆ 0 │
│ 2 ┆ 0 │
│ 2 ┆ 0 │
│ 3 ┆ 1 │
│ 10 ┆ 2 │
└──────┴──────┘
fill_nan(x: Expr) -> Expr
填充nan为null
fill_null(x: Expr, value=0) -> Expr
填充null为value
float_(a: Expr) -> Expr
int转成float
int_(a: Expr) -> Expr
bool转int
left_tail(x: Expr, maximum: float = 0) -> Expr
NaN everything greater than maximum, maximum should be constant.
Examples:
df = pl.DataFrame({
'a': [None, 1, 2, 3, 4, 5],
}).with_columns(
out=left_tail(pl.col('a'), 3),
)
shape: (6, 2)
┌──────┬──────┐
│ a ┆ out │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞══════╪══════╡
│ null ┆ null │
│ 1 ┆ 1 │
│ 2 ┆ 2 │
│ 3 ┆ 3 │
│ 4 ┆ null │
│ 5 ┆ null │
└──────┴──────┘
See Also
tail
References
https://platform.worldquantbrain.com/learn/operators/detailed-operator-descriptions#left_tail
lit_(a: Expr) -> Expr
将常量封装成lit
logit(x: Expr) -> Expr
对数几率,拉伸中间部分
nop(x: Expr) -> Expr
空操作
purify(x: Expr) -> Expr
Clear infinities (+inf, -inf) by replacing with null.
Examples:
df = pl.DataFrame({
'a': [None, 1., 2., float('nan'), float('inf'), float('-inf')],
}).with_columns(
out=purify(pl.col('a')),
)
shape: (6, 2)
┌──────┬──────┐
│ a ┆ out │
│ --- ┆ --- │
│ f64 ┆ f64 │
╞══════╪══════╡
│ null ┆ null │
│ 1.0 ┆ 1.0 │
│ 2.0 ┆ 2.0 │
│ NaN ┆ null │
│ inf ┆ null │
│ -inf ┆ null │
└──────┴──────┘
right_tail(x: Expr, minimum: float = 0) -> Expr
NaN everything less than minimum, minimum should be constant.
Examples:
df = pl.DataFrame({
'a': [None, 1, 2, 3, 4, 5],
}).with_columns(
out=right_tail(pl.col('a'), 3),
)
shape: (6, 2)
┌──────┬──────┐
│ a ┆ out │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞══════╪══════╡
│ null ┆ null │
│ 1 ┆ null │
│ 2 ┆ null │
│ 3 ┆ 3 │
│ 4 ┆ 4 │
│ 5 ┆ 5 │
└──────┴──────┘
References
https://platform.worldquantbrain.com/learn/operators/detailed-operator-descriptions#right_tail
sigmoid(x: Expr) -> Expr
sigmoid激活函数
tail(x: Expr, lower: float = 0, upper: float = 0, newval: float = 0) -> Expr
If (x > lower AND x < upper) return newval, else return x. Lower, upper, newval should be constants.
Examples:
df = pl.DataFrame({
'a': [None, 1, 2, 3, 4, 5, 6],
}).with_columns(
out=tail(pl.col('a'), 2, 5, 1),
)
shape: (7, 2)
┌──────┬──────┐
│ a ┆ out │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞══════╪══════╡
│ null ┆ null │
│ 1 ┆ 1 │
│ 2 ┆ 2 │
│ 3 ┆ 1 │
│ 4 ┆ 1 │
│ 5 ┆ 5 │
│ 6 ┆ 6 │
└──────┴──────┘
See Also
clamp
References
https://platform.worldquantbrain.com/learn/operators/detailed-operator-descriptions#tail