How to change the starting index of iterrows()?
Question:
We can use the following to iterate rows of a data frame.
for index, row in df.iterrows():
What if I want to begin from a different row index? (not from first row)?
Answers:
Sure:
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
Try using itertools.islice
from itertools import islice
for index, row in islice(df.iterrows(), 1, None):
i know this has an answer, but why not just do:
for i, r in df.iloc[1:].iterrows():
We can use the following to iterate rows of a data frame.
for index, row in df.iterrows():
What if I want to begin from a different row index? (not from first row)?
Sure:
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
Try using itertools.islice
from itertools import islice
for index, row in islice(df.iterrows(), 1, None):
i know this has an answer, but why not just do:
for i, r in df.iloc[1:].iterrows():