pandas.Series.str.len #
- 系列.str。len ( ) [来源] #
计算系列/索引中每个元素的长度。
元素可以是序列(例如字符串、元组或列表)或集合(例如字典)。
- 返回:
- int 的系列或索引
整数值的系列或索引,指示系列或索引中每个元素的长度。
也可以看看
str.len
Python 内置函数返回对象的长度。
Series.size
返回系列的长度。
例子
返回字符串中的长度(字符数)。返回字典、列表或元组的条目数。
>>> s = pd.Series(['dog', ... '', ... 5, ... {'foo' : 'bar'}, ... [2, 3, 5, 7], ... ('one', 'two', 'three')]) >>> s 0 dog 1 2 5 3 {'foo': 'bar'} 4 [2, 3, 5, 7] 5 (one, two, three) dtype: object >>> s.str.len() 0 3.0 1 0.0 2 NaN 3 1.0 4 4.0 5 3.0 dtype: float64