itertuples(): 按行遍历,将DataFrame的每一行迭代为元祖,可以通过row[name]对元素进行访问,比iterrows()效率高。...iteritems():按列遍历,将DataFrame的每一列迭代为(列名, Series)对,可以通过row[index]对元素进行访问。...示例数据
import pandas as pd
inp = [{‘c1’:10, ‘c2’:100}, {‘c1’:11, ‘c2’:110}, {‘c1’:12, ‘c2’:123}]
df =...row, ‘name’)
for row in df.itertuples():
print(getattr(row, ‘c1’), getattr(row, ‘c2’)) # 输出每一行
1
2
按列遍历...df.iteritems():
print(index) # 输出列名
1
2
for row in df.iteritems():
print(row[0], row[1], row[2]) # 输出各列