items method only exists in python3 · Issue #17213 · pandas-dev/pandas (original) (raw)

Code Sample, a copy-pastable example if possible

for k, c in df.items(): ...

Problem description

This works on python3 and fails on python2. This seems like a natural thing to do to have easy duck-typing between dataframes and dicts of iterables.

Either the docs should be updated to flag this as a python3 only feature or items should be shimmed onto DataFrames for all versions of python. In python2 this would have different semantics than dict.item given DataFrame has not had item before you are not changing behavior and the 'iterator-not-a-list' semantics are better.

It looks like the initial shim came in via 16dbeab .

As a side-note, six.iteritems works as expected on DataFrames.

Expected Output

it does not raise.

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 2.7.13.final.0
python-bits: 64
OS: Linux
OS-release: 4.11.9-1-ARCH
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: None.None

pandas: 0.20.3
pytest: 3.2.0
pip: 9.0.1
setuptools: 36.2.2.post20170724
Cython: None
numpy: 1.13.1
scipy: 0.19.1
xarray: None
IPython: 5.3.0
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.0.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.9.5
s3fs: None
pandas_gbq: None
pandas_datareader: None