DataFrame.items
以(column name, Series)方式遍历DataFrame的列。
Yields
label | 被迭代的DataFrame的列名 |
---|---|
content | 每个标签的列条目,作为一个Series |
Example
import pandas as pd
df = 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)
--------------------------------------------------------------------
site
first google
second baidu
third wiki
forth pandas
Name: site, dtype: object
age
first 18
second 39
third 22
forth 45
Name: age, dtype: int64
price
first 1.0
second 2.0
third 3.0
forth 4.0
Name: price, dtype: float64
color
first red
second black
third blue
forth red
Name: color, dtype: object