跳转至

foundryts.functions.where

foundryts.functions.where(true=None, false=None)

(DEPRECATED) Returns a function that transforms non-zero and zero values with the specified functions for truthy and falsey values, respectively.

  • Parameters:
  • true (FunctionNode | int | float, optional) – Function or value to transform the non-zero values using (default is None leaving non-zero values unchanged).
  • false (FunctionNode | int | float, optional) – Function or value to transform the zero values using (default is None leaving zero values unchanged).
  • Returns: A function that accepts a single time series and transforms non-zero and zero values with the specified functions for truthy and falsey values, respectively.
  • Return type: (FunctionNode) -> FunctionNode

Dataframe schema

Column name Type Description
timestamp pandas.Timestamp Timestamp of the point
value float Value of the point

:::callout{theme="warning" title="Note"} This function is Deprecated and will be removed in a future release. :::

Examples

>>> series = F.points(
...     (1, 1.0),
...     (2, 0.0),
...     (3, 0.0),
...     name="series",
... )
>>> series.to_pandas()
                      timestamp  value
0 1970-01-01 00:00:00.000000001    1.0
1 1970-01-01 00:00:00.000000002    0.0
2 1970-01-01 00:00:00.000000003    0.0
>>> transformed_series = F.where(true=series * 2, false=-1)(series)
>>> transformed_series.to_pandas()
                      timestamp  value
0 1970-01-01 00:00:00.000000001    2.0
1 1970-01-01 00:00:00.000000002   -1.0
2 1970-01-01 00:00:00.000000003   -1.0

中文翻译

# foundryts.functions.where

## foundryts.functions.where(true=None, false=None)

(已弃用)返回一个函数,该函数分别使用指定的真值函数和假值函数对非零值和零值进行转换。

* **参数:**
  * **true**`FunctionNode` | int | float,可选)– 用于转换非零值的函数或值(默认为 `None`,即保持非零值不变)。
  * **false**`FunctionNode` | int | float,可选)– 用于转换零值的函数或值(默认为 `None`,即保持零值不变)。
* **返回值:**
  一个接受单个时间序列的函数,并分别使用指定的真值函数和假值函数对非零值和零值进行转换。
* **返回类型:**
  (`FunctionNode`) -> `FunctionNode`

## 数据框架模式(Dataframe schema)

| 列名        | 类型               | 描述           |
|-------------|--------------------|----------------|
| timestamp   | pandas.Timestamp   | 数据点的时间戳 |
| value       | float              | 数据点的值     |

:::callout{theme="warning" title="注意"}
此函数已弃用,将在未来版本中移除。
:::

## 示例

```pycon
>>> series = F.points(
...     (1, 1.0),
...     (2, 0.0),
...     (3, 0.0),
...     name="series",
... )
>>> series.to_pandas()
                      timestamp  value
0 1970-01-01 00:00:00.000000001    1.0
1 1970-01-01 00:00:00.000000002    0.0
2 1970-01-01 00:00:00.000000003    0.0

>>> transformed_series = F.where(true=series * 2, false=-1)(series)
>>> transformed_series.to_pandas()
                      timestamp  value
0 1970-01-01 00:00:00.000000001    2.0
1 1970-01-01 00:00:00.000000002   -1.0
2 1970-01-01 00:00:00.000000003   -1.0
```