w3resource logo

:

Python Exercises

Python Pandas: Iterate over rows in a DataFrame

Python Pandas: DateFrame Exercise-21 with Solution

Write a Python program to iterate over rows in a DataFrame.

Sample Solution :-

Python Code :

import pandas as pd
import numpy as np
exam_data = [{'name':'Anastasia', 'score':12.5}, {'name':'Dima','score':9}, {'name':'Katherine','score':16.5}]
df = pd.DataFrame(exam_data)
for index, row in df.iterrows():
    print(row['name'], row['score'])

Sample Output:

Anastasia 12.5                                                         
Dima 9.0                                                               
Katherine 16.5                   

Python Code Editor:

Improve this sample solution and post your code through Disqus