python
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'])
#prints
# John 100
# Eric 110
# Rick 120
Was this helpful?
Similar Posts