File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -615,12 +615,16 @@ def iterrows(self):
615
615
s .name = k
616
616
yield k , s
617
617
618
- def itertuples (self ):
618
+ def itertuples (self , index = True ):
619
619
"""
620
620
Iterate over rows of DataFrame as tuples, with index value
621
621
as first element of the tuple
622
622
"""
623
- return izip (self .index , * self .values .T )
623
+ arrays = []
624
+ if index :
625
+ arrays .append (self .index )
626
+ arrays .extend (self [k ] for k in self .columns )
627
+ return izip (* arrays )
624
628
625
629
iterkv = iteritems
626
630
if py3compat .PY3 : # pragma: no cover
Original file line number Diff line number Diff line change @@ -2544,6 +2544,12 @@ def test_itertuples(self):
2544
2544
expected = self .frame .ix [i ,:].reset_index (drop = True )
2545
2545
assert_series_equal (s , expected )
2546
2546
2547
+ df = DataFrame ({'floats' : np .random .randn (5 ),
2548
+ 'ints' : range (5 )}, columns = ['floats' , 'ints' ])
2549
+
2550
+ for tup in df .itertuples (index = False ):
2551
+ self .assert_ (isinstance (tup [1 ], np .integer ))
2552
+
2547
2553
def test_len (self ):
2548
2554
self .assertEqual (len (self .frame ), len (self .frame .index ))
2549
2555
You can’t perform that action at this time.
0 commit comments