Pandas Series: str.len() function
Series-str.len() function
The str.len() function is used to compute the length of each element in the Series/Index.
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).
Syntax:
Series.str.len(self)
Returns: Series or Index of int
A Series or Index of integer values indicating the length of each element in the Series or Index.
Example - Returns the length (number of characters) in a string. Returns the number of entries for dictionaries, lists or tuples:
Python-Pandas Code:
import numpy as np
import pandas as pd
s = pd.Series(['fox',
'',
6,
{'f1' : 'b1'},
[3, 5, 7, 9],
('one', 'two', 'three')])
s
Output:
0 fox 1 2 6 3 {'f1': 'b1'} 4 [3, 5, 7, 9] 5 (one, two, three) dtype: object
Python-Pandas Code:
import numpy as np
import pandas as pd
s = pd.Series(['fox',
'',
6,
{'f1' : 'b1'},
[3, 5, 7, 9],
('one', 'two', 'three')])
s.str.len()
Output:
0 3.0 1 0.0 2 NaN 3 1.0 4 4.0 5 3.0 dtype: float64
Previous: Series-str.join() function
Next: Series-str.lower() function
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/pandas/series/series-str-len.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics