米脂
我建议使用pandas内置的iterrows函数。data = {'Name': ['John', 'Paul', 'George'], 'Age': [20, 21, 19]} db = pd.DataFrame(data) print(f"Dataframe:\n{db}\n") for row, col in db.iterrows(): print(f"Row Index:{row}") print(f"Column:\n{col}\n")上面的输出:Dataframe: Name Age0 John 201 Paul 212 George 19Row Index:0Column:Name JohnAge 20Name: 0, dtype: objectRow Index:1Column:Name PaulAge 21Name: 1, dtype: objectRow Index:2Column:Name GeorgeAge 19Name: 2, dtype: object