Series 是一种类似于一维数组的对象,它由一组数据(各种NumPy数据类型)以及一组与之 相关的数据标签(即索引)组成。
一、对于Series定义的理解
1.Series像是一个Python的dict类型,因为它的索引与元素是映射关系
2. Series也像是一个ndarray类型,因为它也可以通过series_name[index]方式访问
3. Series是一维的,但能够存储不同类型的数据
4.每个Series都有一组索引与数据对应,若不指定则默认为整型索引
5.不显式指定index
二、Series常用属性

三、Series常用函数


四、Series基本用法
1.常规查询:使用索引,或者使用序号
series0 = Series(np.array(range(3)), index = ["first", "second", "third"], dtype=int)
print(series0[1])
print("#" * 30)
print(series0["first"])
2.切片查询
(1)索引切片,闭区间
(2)序号切片,前闭后开
series0 = Series(np.array(range(3)), index = ["first", "second", "third"], dtype=int)
print(series0["second": "third"])
print("#" * 30)
print(series0[1:2])
second 1
third 2
dtype: int32
##############################
second 1
dtype: int32
3、条件查询
series0 = Series(np.array(range(3)), index = ["first", "second", "third"], dtype=int)
print(series0[series0 > 0])
second 1
third 2
dtype: int32
4、新增
series0 = Series(np.array(range(3)), index = ["first", "second", "third"], dtype=int)
series0["fourth"] = 3
print(series0)
first 0
second 1
third 2
fourth 3
dtype: int64
5、删除
只能根据索引进行删除,无法直接删除值
series0 = Series(np.array(range(3)), index = ["first", "second", "third"], dtype=int)
series0 = series0.drop("third")
print(series0)
first 0
second 1
dtype: int32
6、修改
series0 = Series(np.array(range(3)), index = ["first", "second", "third"], dtype=int)
series0["first"] = "first-modify"
print(series0)
series0[1] = "second-modify"
print(series0)
first first-modify
second 1
third 2
dtype: object
first first-modify
second second-modify
third 2
dtype: object