polars.Series.cat.len_chars#

Series.cat.len_chars() Series[source]#

Return the number of characters of the string representation of each value.

Returns:
Series

Series of data type UInt32.

See also

len_bytes

Notes

When working with ASCII text, use len_bytes() instead to achieve equivalent output with much better performance: len_bytes() runs in _O(1)_, while len_chars() runs in (_O(n)_).

A character is defined as a Unicode scalar value. A single character is represented by a single byte when working with ASCII text, and a maximum of 4 bytes otherwise.

Examples

>>> s = pl.Series(["Café", "345", "東京", None], dtype=pl.Categorical)
>>> s.cat.len_chars()
shape: (4,)
Series: '' [u32]
[
    4
    3
    2
    null
]