1.Series数据结构
【思考与练习】
创建并访问Series对象。
1
)创建如下表的
Series
数据对象,其中
a-f
为索引;
2
)增加数据
27
,索引为
g
;
3
)修改索引
d
对应的值为
40
;
4
)查询值大于
27
的数据;
5
)删除位置为
1-3
的数据。
【提示】位置
1-3
的索引列表,可以用
series.index[1:3]
来得到。
from pandas import Series
#创建如下表的Series数据对象,其中a-f为索引
s1 = Series([30,25,27,41,25,34],index=['a','b','c','d','e','f'])
#增加数据27,索引为g
a = Series([27],index = ['g'])#仅有一组数据也需要加[]
news1 = s1.append(a)
#修改索引d对应的值为40
news1['d'] = 40 #查询,修改都要用[]
#查询值大于27的数据
news1[news1.values>27] #查询,修改都要用[]
#删除位置为1-3的数据
news2 = news1.drop(news1.index[1:3])
2.Dataframe数据结构