How to change the starting index of iterrows ()?

We can use the following to iterate the rows of a data frame.

for index, row in df.iterrows(): 

What if I want to start with a different row index? (not from the first line)?

+7
python pandas dataframe
source share
3 answers

Try using itertools.islice

 from itertools import islice for index, row in islice(df.iterrows(), 1, None): 
+9
source share

I know this has an answer, but why not just do:

 for i, r in df.iloc[1:].iterrows(): 
+8
source share

Of course:

 for i,(index,row) in enumerate(df.iterrows()): if i == 0: continue # skip first row 

Or something like:

 for i,(index,row) in enumerate(df.iterrows()): if i < 5: continue # skip first 5 rows 
0
source share

All Articles