How to Iterate Over Rows in a Pandas DataFrame?
Iterate over the rows in Pandas DataFrame using the iterrows method of the data frame.
import pandas as pd
df = pd.DataFrame({'colA': [1, 2, 3], 'colB': [2, 4, 8]})
for index, row in df.iterrows():
print(row['colA'], row['colB'])
'''
Output:
1 2
2 4
3 8
'''
However, iterating over the rows in Pandas DataFrame is considered an anti-pattern, and is recommended only when there is no other option.