Skip to content

featurebyte.CastToNumeric

class CastToNumeric(
*,
type: Literal["cast_to_numeric"]="cast_to_numeric",
target_dtype: Literal["INT", "FLOAT"]
)

Description

CastToNumeric class is used to declare the operation to cast varchar column values to numeric types (INT or FLOAT). This cleaning operation is designed for varchar columns that contain numeric values stored as strings. It attempts to cast the string values to the specified target data type (INT or FLOAT). Values that cannot be successfully cast will be converted to NULL.

Parameters

  • type: Literal["cast_to_numeric"]
    default: "cast_to_numeric"

  • target_dtype: Literal["INT", "FLOAT"]
    The target numeric data type to cast to. Must be either DBVarType.INT or DBVarType.FLOAT.

Examples

Create a cleaning operation to cast varchar column values to integer type:

>>> fb.CastToNumeric(target_dtype=fb.enum.DBVarType.INT)

Create a cleaning operation to cast varchar column values to float type:
>>> fb.CastToNumeric(target_dtype=fb.enum.DBVarType.FLOAT)