Pandas DataFrame __iter__() Method
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.