Pandas Series: str.get() function
Series-str.get() function
The str.get() function is used to extract element from each component at specified position.
Extract element from lists, tuples, or strings in each element in the Series/Index.
Syntax:
Series.str.get(self, i)
Parameters:
Name | Description | Type/Default Value | Required / Optional |
---|---|---|---|
i | Position of element to extract. | int | Required |
Returns: Series or Index
Example:
Python-Pandas Code:
import numpy as np
import pandas as pd
s = pd.Series(["String",
(2, 3, 4),
["p", "q", "r"],
234,
-567,
{1: "Hiii", "2": "friends"}])
s
Output:
0 String 1 (2, 3, 4) 2 [p, q, r] 3 234 4 -567 5 {1: 'Hiii', '2': 'friends'} dtype: object
Python-Pandas Code:
import numpy as np
import pandas as pd
s = pd.Series(["String",
(2, 3, 4),
["p", "q", "r"],
234,
-567,
{1: "Hiii", "2": "friends"}])
s.str.get(1)
Output:
0 t 1 3 2 q 3 NaN 4 NaN 5 Hiii dtype: object
Python-Pandas Code:
import numpy as np
import pandas as pd
s = pd.Series(["String",
(2, 3, 4),
["p", "q", "r"],
234,
-567,
{1: "Hiii", "2": "friends"}])
s.str.get(-1)
Output:
0 g 1 4 2 r 3 NaN 4 NaN 5 None dtype: object
Previous: Series-str.findall() function
Next: Series-str.join() 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-get.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics