9.3 Indexing with .str
You can use []
notation to directly index by position locations. If you index past the end
of the string, the result will be a NaN
.
In [1]: s = pd.Series(['A', 'B', 'C', 'Aaba', 'Baca', np.nan,
...: 'CABA', 'dog', 'cat'])
...:
In [2]: s.str[0]
Out[2]:
0 A
1 B
2 C
3 A
...
5 NaN
6 C
7 d
8 c
dtype: object
In [3]: s.str[1]
Out[3]:
0 NaN
1 NaN
2 NaN
3 a
...
5 NaN
6 A
7 o
8 a
dtype: object