pandas.Series.str.len#
- Series.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