pandas.Series.str.len¶
Compute the length of each element in the Series/Index. The element may be a sequence (such as a string, tuple or list) or a collection (such as a dictionary).
- return
Series or Index of int A Series or Index of integer values indicating the length of each element in the Series or Index.
Limitations¶
Series elements are expected to be Unicode strings. Elements cannot be NaNs.
Examples¶
import pandas as pd
from numba import njit
@njit
def series_str_len():
series = pd.Series(['foo', 'bar', 'foobar']) # Series of 'foo', 'bar', 'foobar'
out_series = series.str.len()
return out_series # Expect series of 3, 3, 6
print(series_str_len())
$ python ./series/str/series_str_len.py
0 3
1 3
2 6
dtype: int64
See also
- str.len
Python built-in function returning the length of an object.
- Series.size
Returns the length of the Series.