DataFrame.items
以(column name, Series)方式遍历DataFrame的列。
Yields
| label | 被迭代的DataFrame的列名 |
|---|---|
| content | 每个标签的列条目,作为一个Series |
Example
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 label, col in df.items():print(label)print(col)--------------------------------------------------------------------sitefirst googlesecond baiduthird wikiforth pandasName: site, dtype: objectagefirst 18second 39third 22forth 45Name: age, dtype: int64pricefirst 1.0second 2.0third 3.0forth 4.0Name: price, dtype: float64colorfirst redsecond blackthird blueforth redName: color, dtype: object
