目录
Series包含了一个值序列,且包含了数据标签(索引)
一 创建
from pandas import Series
1 直输创建
① 默认序列index
- a = [1, 2 ,3 ]
- s = Series ( a )
查看创建的index和对应的值
- s.index
- s.values
② 创建时指定index
- s1 = series ( a ,index = ['A' , 'B', 'C' ]
- s1. index
2 用arange创建
引入numpy;arange 从0开始默认
- import numpy as np
- S2 = Series ( np. arange(5) )
3 结合字典
① 用字典创建
- d = { 'A' : 1, 'B' : 2, 'C' :3 }
- s3 = Series ( d )
② 把Series 转换成 字典
- s3. to_dict ( )
二 访问
1 用index访问values
-
s3 [ 'A' ]
-
2 表达式 条件访问
访问值是大于1的Series
- s3 [ s3 > 1 ]
查看条件访问后的类型
- type ( s3 [ s3 > 1 ] )
三 扩充
1 用index 增删
现s3如下,将其扩充,命名s4
- s4 = Series ( s3 ,index = [ 'A', 'B', 'C' ,'D' ]
增加index就可以扩充了,删除同理 少写字母就好
2 补充 isnull、notnull
① isnull
是null的则返回为 True
- s4. isnull ()
② notnull
notnull 和isnull相反
- s4. notnull ()