polars.Series.cast#
- Series.cast(
- dtype: type[int | float | str | bool] | PolarsDataType,
- *,
- strict: bool = True,
- wrap_numerical: bool = False,
在数据类型之间进行转换。
- Parameters:
- dtype
要转换到的数据类型。
- strict
如果为True,无效的转换将生成异常而不是
null。- wrap_numerical
如果为True,数值转换将包裹溢出值,而不是将转换标记为无效。
示例
>>> s = pl.Series("a", [True, False, True]) >>> s shape: (3,) Series: 'a' [bool] [ true false true ]
>>> s.cast(pl.UInt32) shape: (3,) Series: 'a' [u32] [ 1 0 1 ]