Tutorials References Exercises Videos Menu
Create Website Get Certified Upgrade

Pandas DataFrame __iter__() Method

❮ DataFrame Reference


Example

Return the column labels:

import pandas as pd

data = {
  "firstname": ["Sally", "Mary", "John"],
  "age": [50, 40, 30]
}

df = pd.DataFrame(data)

for x in df.__iter__():
  print(x)
Try it Yourself »

Definition and Usage

The __iter__() method creates a Python iterator object that iterates over the index axis.


Syntax

dataframe.__iter__()

Parameters

The __iter__() method takes no parameters.


Return Value

A Python iterator object.


❮ DataFrame Reference