Python数据分析学习(二)
1. Series的取值
1.1 values
from pandas import Series
emp = ['001','002','003']
name = ['王者','青铜','黑铁']
se = Series(data=name,index=emp)
print(se)
print(se.values)
运行结果:
001 王者
002 青铜
003 黑铁
dtype: object
['王者' '青铜' '黑铁']
values获取数据的值,返回list类型
1.2 index
print(se.index)
运行结果:
Index(['001', '002', '003'], dtype='object')
index获取索引的值,返回index类型
to_list进行转换成列表
print(se.index.to_list())
运行结果:
['001', '002', '003']
1.3 items
print(se.items())
运行结果:
<zip object at 0x00000219A7734080>
items获取每对索引和值,返回zip类型
使用list()转换成列表
print(list(se.items()))
运行结果:
[('001', '王者'), ('002', '青铜'), ('003', '黑铁')]
1.4 使用下标取值
1.4.1 标签索引下标
print(se[['001','003']])
运行结果:
001 王者
003 黑铁
dtype: object
1.4.2 位置索引下标
print(se[[0,2]