码迷,mamicode.com
首页 > 其他好文 > 详细

pandas_Series

时间:2018-01-11 23:49:52      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:存在   索引   操作   nan   gpo   pos   运算   nbsp   数组   

1.Series出现原因:当系统需要字典式的数组,需要用到map数据结构,但是map结构是无序的,不支持排序。Seires结构综合了list和map的特点

2.使用数组生成索引

#用数组生成Series
obj = Series([4, 7, -5, 3])
#指定Series的index
obj2 = Series([4, 7, -5, 3], index = [d, b, a, c])

3.使用字典生成索引

#使用字典生成Series
sdata = {Ohio:45000, Texas:71000, Oregon:16000, Utah:5000}
obj3 = Series(sdata)
#使用字典生成Series,并额外指定index,不匹配部分为NaN
states = [California, Ohio, Oregon, Texas]
obj4 = Series(sdata, index = states)

4.简单运算

#Series相加,相同索引部分相加
obj3 + obj4
#指定Series及其索引的名字
obj4.name = population
obj4.index.name = state
#替换index
obj.index = [Bob, Steve, Jeff, Ryan]

注:Seires只有name和index.name两列

5.基本操作

#对象
obj
#
obj.values
#索引
obj.index
# 找出大于0的元素
print obj2[obj2 > 0] 
# 判断索引是否存在
 print b in obj2 

 

pandas_Series

标签:存在   索引   操作   nan   gpo   pos   运算   nbsp   数组   

原文地址:https://www.cnblogs.com/helloandhey/p/8270753.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!