-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
Closed
Labels
ReshapingConcat, Merge/Join, Stack/Unstack, ExplodeConcat, Merge/Join, Stack/Unstack, ExplodeUsage Question
Description
I don't know if this is a doc bug, a code bug, or an expectation error on my part.
The documentation of itertuples says this function will "Iterate over DataFrame rows as namedtuples", but the resulting items are not namedtuple and cannot be indexed by name like a namedtuple.
Code Sample, a copy-pastable example if possible
import pandas as pd
df = pd.DataFrame({'col1': [1, 2], 'col2': [0.1, 0.2]},
index=['a', 'b'])
for row in df.itertuples():
print(row)
print(row['col1'])
$ python pandasbug.py
Pandas(Index='a', col1=1, col2=0.10000000000000001)
Traceback (most recent call last):
File "pandasbug.py", line 8, in <module>
print(row['col1'])
TypeError: tuple indices must be integers, not str
Expected Output
$ python pandasbug.py
Pandas(Index='a', col1=1, col2=0.10000000000000001)
1
Pandas(Index='b', col1=2, col2=0.20000000000000001)
2
output of pd.show_versions()
$ python -c 'import pandas as pd; pd.show_versions()'
INSTALLED VERSIONS
------------------
commit: None
python: 2.7.6.final.0
python-bits: 64
OS: Linux
OS-release: 3.13.0-45-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
pandas: 0.18.0
nose: None
pip: 8.1.1
setuptools: 2.2
Cython: None
numpy: 1.11.0
scipy: None
statsmodels: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.5.2
pytz: 2016.3
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: None
openpyxl: None
xlrd: 0.9.4
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.12
pymysql: None
psycopg2: 2.6.1 (dt dec pq3 ext)
jinja2: None
boto: None
suzil and AndrewsOR
Metadata
Metadata
Assignees
Labels
ReshapingConcat, Merge/Join, Stack/Unstack, ExplodeConcat, Merge/Join, Stack/Unstack, ExplodeUsage Question