Pandas Loop Dataframe

February 21, 2021
import pandas as pd 

items = [
  {'name': 'Desmond', 'rank': 1},
  {'name': 'Jack', 'rank': 2},
  {'name': 'Elon', 'rank': 3}
]

df = pd.DataFrame(items) 

for index, row in df.iterrows():
  print(index, row['name'], row['rank'])

or

for i in range(len(df)):
  print(df.index[i], df['name'][i], df['rank'][i])
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.