Unexpected behavior of the str attribute which is working with Series of list #25240
Labels
Docs
Nested Data
Data where the values are collections (lists, sets, dicts, objects, etc.).
Strings
String extension data type and string data
Code Sample, a copy-pastable example if possible
import pandas as pd
s1 = pd.Series(['AA/aa', 'BB/bb', 'CC/cc'])
s2 = s1.str.split('/')
s2.str[0]
Result:
0 AA
1 BB
2 CC
dtype: object
Problem description
In this example, the second 'str' attribute is applyied to a Series of list and not to a Series of string.
Then the [] operator works fine with each list an retrieve their first element...
As it is an unexpected working behavior, one may wonder if it is secure to code like this (instead of working with an apply + lambda for instance). This works also with Series of dict, and probably with any object implementing the [] operator.
Expected Output
Warning or error?
Or a word in the documentation?
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.4.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 69 Stepping 1, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.23.4
pytest: 3.3.2
pip: 19.0.1
setuptools: 38.4.0
Cython: 0.27.3
numpy: 1.14.2
scipy: 1.0.0
pyarrow: None
xarray: 0.10.9
IPython: 6.2.1
sphinx: 1.6.6
patsy: 0.5.0
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.4
feather: None
matplotlib: 2.1.2
openpyxl: 2.5.12
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.2
lxml: 4.2.3
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.2.1
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: