series_fill_const()series_fill_const()

用指定的常数值替换序列中缺失的值。Replaces missing values in a series with a specified constant value.

采用包含动态数值数组作为输入的表达式,将 missing_value_placeholder 的所有实例替换为指定的 constant_value 并返回生成的数组。Takes an expression containing dynamic numerical array as input, replaces all instances of missing_value_placeholder with specified constant_value and returns the resulting array.

语法Syntax

series_fill_const(x[, constant_value[, missing_value_placeholder]])series_fill_const(x[, constant_value[, missing_value_placeholder]])

  • 将返回序列 x,其中的所有 missing_value_placeholder 实例都被替换为 constant_value。Will return series x with all instances of missing_value_placeholder replaced with constant_value.

参数Arguments

  • x:动态数组标量表达式(数值数组)。x: dynamic array scalar expression that is an array of numeric values.
  • constant_value:此参数指定要替换的缺失值的占位符。constant_value: parameter that specifies a placeholder for a missing value to be replaced. 默认值为 0。Default value is 0.
  • missing_value_placeholder:可选参数,用于指定要替换的缺失值的占位符。missing_value_placeholder: optional parameter that specifies a placeholder for a missing value to be replaced. 默认值为“double(null)”。Default value is double(null).

备注Notes

  • 可以通过使用 default = DefaultValue 语法(或直接省略此项,这样就会假定其为 0)来创建使用常量值填充的序列。You can create a series that fills with a constant value by using default = DefaultValue syntax (or just omitting that will assume 0). 有关详细信息,请参阅 make-seriesFor more information, see make-series.
make-series num=count() default=-1 on TimeStamp from ago(1d) to ago(1h) step 1h by Os, Browser
  • 若要在 make-series 之后应用任何内插函数,请指定“null”作为默认值:To apply any interpolation functions after make-series, specify null as a default value:
make-series num=count() default=long(null) on TimeStamp from ago(1d) to ago(1h) step 1h by Os, Browser
  • missing_value_placeholder 可以是将转换为实际元素类型的任何类型。The missing_value_placeholder can be of any type, which will be converted to actual element types. 因此,“double(null)”、“long(null)”或“int(null)”的含义相同。As such, either double(null), long(null) or int(null) have the same meaning.
  • 此函数会保留数组元素的原始类型。The function preserves original type of the array elements.

示例Example

let data = datatable(`arr`: dynamic)
[
    dynamic([111,null,36,41,23,null,16,61,33,null,null])   
];
data 
| project arr, 
          fill_const1 = series_fill_const(arr, 0.0),
          fill_const2 = series_fill_const(arr, -1)  
arr fill_const1 fill_const2
[111,null,36,41,23,null,16,61,33,null,null][111,null,36,41,23,null,16,61,33,null,null] [111,0.0,36,41,23,0.0,16,61,33,0.0,0.0][111,0.0,36,41,23,0.0,16,61,33,0.0,0.0] [111,-1,36,41,23,-1,16,61,33,-1,-1][111,-1,36,41,23,-1,16,61,33,-1,-1]