In this python pandas program, we will iterate over rows in a DataFrame using pandas library.
Steps to solve the program
- Import pandas library as pd.
- Create a dataframe using pd.DataFrame().
- Iterate over rows in a DataFrame using for loop and df.iterrows().
- Print the records for each column using row[column1],row[columns2],……,row[column_n].
import pandas as pd
import numpy as np
d = [{'name':'Yash','percentage':78},{'name':'Rakesh','percentage':80},{'name':'Suresh','percentage':60}]
df = pd.DataFrame(d)
for index, row in df.iterrows():
print(row['name'], row['percentage'])
Output :
Yash 78
Rakesh 80
Suresh 60