Chrome Extension

Loop through DataFrame rows in python pandas

DataFrame iterrows() method can be used to loop through or iterate over Dataframe rows. You can get the value of a row by its column name in each iteration.
import pandas as pd

df = pd.DataFrame({
    'column_1': ['John', 'Eric', 'Rick'],
    'column_2': [100, 110, 120]

for index, row in df.iterrows():
    print(row['column_1'], row['column_2'])

# John 100
# Eric 110
# Rick 120
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

Search Index Data (The code snippet can also be found with below search text)

iterate DataFrame rows in python pandas
Was this helpful?
Join Devsheet Ask a Question