DataFrame.iterrows
以(index, Series)遍历DataFrame的行。
Yields
| index | 行的索引。MultiIndex的元组 |
|---|---|
| data | 行的数据,作为一个Series |
import pandas as pddf = pd.DataFrame({'site':['google', 'baidu', 'wiki', 'pandas'],'age':[18, 39, 22, 45],'price': [1.0, 2.0, 3.0, 4.0],'color': ['red', 'black', 'blue', 'red']}, index=['first', 'second', 'third', 'forth'])for index, row in df.iterrows():print(index)print(row)-------------------------------------------firstsite googleage 18price 1color redName: first, dtype: objectsecondsite baiduage 39price 2color blackName: second, dtype: objectthirdsite wikiage 22price 3color blueName: third, dtype: objectforthsite pandasage 45price 4color redName: forth, dtype: object
