跳转至

foundryts.functions.value_shift

foundryts.functions.value_shift(delta)

Returns a function that shifts all values of a single time series by the specified delta.

For a source time series with points (timestamp, value), upon shifting by delta, the resulting value-shifted time series will have points (timestamp, value + delta).

  • Parameters: delta (int) – The amount by which to shift the value of each point.
  • Returns: A function that accepts a single time series as input and returns the value-shifted time series.
  • Return type: (FunctionNode) -> FunctionNode

Dataframe schema

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

:::callout{theme="success" title="See Also"} timestamp_scale(), time_shift() :::

:::callout{theme="warning" title="Note"} This function is only applicable to numeric series. :::

Examples

>>> series = F.points(
...     (100, 0.0),
...     (200, float("inf")),
...     (300, 3.14159),
...     (2147483647, 1.0),
...     name="series"
... )
>>> series.to_pandas()
                      timestamp    value
0 1970-01-01 00:00:00.000000100  0.00000
1 1970-01-01 00:00:00.000000200      inf
2 1970-01-01 00:00:00.000000300  3.14159
3 1970-01-01 00:00:02.147483647  1.00000
>>> value_shifted = F.value_shift(3.0)(series)
>>> value_shifted.to_pandas()
                      timestamp    value
0 1970-01-01 00:00:00.000000100  3.00000
1 1970-01-01 00:00:00.000000200      inf
2 1970-01-01 00:00:00.000000300  6.14159
3 1970-01-01 00:00:02.147483647  4.00000
>>> negative_value_shifted = F.value_shift(-3.0)(series)
>>> negative_value_shifted.to_pandas()
                      timestamp    value
0 1970-01-01 00:00:00.000000100 -3.00000
1 1970-01-01 00:00:00.000000200      inf
2 1970-01-01 00:00:00.000000300  0.14159
3 1970-01-01 00:00:02.147483647 -2.00000

中文翻译

foundryts.functions.value_shift

foundryts.functions.value_shift(delta)

返回一个函数,该函数将单个时间序列中的所有值按指定的 delta 进行偏移。

对于包含点 (timestamp, value) 的源时间序列,经过 delta 偏移后,生成的值偏移时间序列将包含点 (timestamp, value + delta)

  • 参数: delta (int) – 每个点的值要偏移的量。
  • 返回值: 一个函数,接受单个时间序列作为输入,并返回值偏移后的时间序列。
  • 返回类型: (FunctionNode) -> FunctionNode

数据框模式(Dataframe schema)

列名 类型 描述
timestamp pandas.Timestamp 点的时间戳
value float 点的偏移后值

:::callout{theme="success" title="另请参阅"} timestamp_scale(), time_shift() :::

:::callout{theme="warning" title="注意"} 此函数仅适用于数值型序列。 :::

示例

>>> series = F.points(
...     (100, 0.0),
...     (200, float("inf")),
...     (300, 3.14159),
...     (2147483647, 1.0),
...     name="series"
... )
>>> series.to_pandas()
                      timestamp    value
0 1970-01-01 00:00:00.000000100  0.00000
1 1970-01-01 00:00:00.000000200      inf
2 1970-01-01 00:00:00.000000300  3.14159
3 1970-01-01 00:00:02.147483647  1.00000
>>> value_shifted = F.value_shift(3.0)(series)
>>> value_shifted.to_pandas()
                      timestamp    value
0 1970-01-01 00:00:00.000000100  3.00000
1 1970-01-01 00:00:00.000000200      inf
2 1970-01-01 00:00:00.000000300  6.14159
3 1970-01-01 00:00:02.147483647  4.00000
>>> negative_value_shifted = F.value_shift(-3.0)(series)
>>> negative_value_shifted.to_pandas()
                      timestamp    value
0 1970-01-01 00:00:00.000000100 -3.00000
1 1970-01-01 00:00:00.000000200      inf
2 1970-01-01 00:00:00.000000300  0.14159
3 1970-01-01 00:00:02.147483647 -2.00000