Skip to content

featurebyte.Target.astype

astype(
new_type: Union[Type[int], Type[float], Type[str], Literal["int", "float", "str"]]
) -> FrozenSeriesT

Description

Convert a Series to have a new type. This is useful for converting a series between a string, and numerical types, or vice-versa.

Parameters

  • new_type: Union[Type[int], Type[float], Type[str], Literal["int", "float", "str"]]
    Desired type after conversion. Type can be provided directly, or as a string.

Returns

  • FrozenSeriesT
    A new Series with converted variable type.

Raises

  • TypeError
    If the Series dtype does not support type conversion.

Examples

Convert a numerical series to a string series, and back to an int series.

>>> event_view = catalog.get_view("GROCERYINVOICE")
>>> event_view["Amount"] = event_view["Amount"].astype(str)
>>> event_view["Amount"] = event_view["Amount"].astype(int)