Skip to content

Commit 06a154f

Browse files
committed
BUG: allow itertuples to work with duplicate columns
1 parent 51cc9d9 commit 06a154f

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

pandas/core/frame.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,9 @@ def itertuples(self, index=True):
818818
arrays = []
819819
if index:
820820
arrays.append(self.index)
821-
arrays.extend(self[k] for k in self.columns)
821+
822+
# use integer indexing because of possible duplicate column names
823+
arrays.extend(self.iloc[:, k] for k in xrange(len(self.columns)))
822824
return izip(*arrays)
823825

824826
iterkv = iteritems

pandas/tests/test_frame.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3951,6 +3951,10 @@ def test_itertuples(self):
39513951
for tup in df.itertuples(index=False):
39523952
self.assert_(isinstance(tup[1], np.integer))
39533953

3954+
df = DataFrame(data={"a": [1, 2, 3], "b": [4, 5, 6]})
3955+
dfaa = df[['a', 'a']]
3956+
self.assertEqual(list(dfaa.itertuples()), [(0, 1, 1), (1, 2, 2), (2, 3, 3)])
3957+
39543958
def test_len(self):
39553959
self.assertEqual(len(self.frame), len(self.frame.index))
39563960

0 commit comments

Comments
 (0)