Pandas Note

Iterate over rows in a DataFrame

iterrows is a generator which yield both index and row

import pandas as pd

df = pd.DataFrame([
    {'Name': 'Abhishek', 'Age': 31},
    {'Name': 'Anurag', 'Age': 20},])

for index, row in df.iterrows():
    print(row['Name'], row['Age'])

tags: pythonpandas