dtoolkit.accessor.series.len#

dtoolkit.accessor.series.len(s: Series, /, number: int = 1, other: int = None) Series[source]#

Return the length of each element in the Series.

Equals to s.apply(len), but the length of number type will as 1, the length of other types will as NaN.

Parameters:
numberint, default 1

The default length of number type.

otherint or None, default None

The default length of other type.

Returns:
Series(int64)

Notes

Examples

>>> import dtoolkit
>>> import pandas as pd
>>> s = pd.Series([0, 1, 1.5, "string", ("tuple",), ["list"], {}, object])
>>> s
0                   0
1                   1
2                 1.5
3              string
4            (tuple,)
5              [list]
6                  {}
7    <class 'object'>
dtype: object
>>> s.len()
0    1.0
1    1.0
2    1.0
3    6.0
4    1.0
5    1.0
6    0.0
7    NaN
dtype: float64

Set number and other default return.

>>> s.len(number=0, other=0)
0    0
1    0
2    0
3    6
4    1
5    1
6    0
7    0
dtype: int64