polars.Series.str.len_chars#
- Series.str.len_chars() Series [source]#
Return the length of each string as the number of characters.
- Returns:
- Series
Series of data type
UInt32
.
See also
Notes
When working with ASCII text, use
len_bytes()
instead to achieve equivalent output with much better performance:len_bytes()
runs in _O(1)_, whilelen_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]) >>> s.str.len_chars() shape: (4,) Series: '' [u32] [ 4 3 2 null ]