當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python pandas.Series.str.len用法及代碼示例

用法:

Series.str.len()

計算係列/索引中每個元素的長度。

元素可以是序列(如字符串、元組或列表)或集合(如字典)。

返回

int 的係列或索引

整數值的係列或索引,指示係列或索引中每個元素的長度。

例子

返回字符串的長度(字符數)。返回字典、列表或元組的條目數。

>>> 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

相關用法


注:本文由純淨天空篩選整理自pandas.pydata.org大神的英文原創作品 pandas.Series.str.len。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。