pandas创建series有哪些方法,常见操作怎样实现
Admin 2022-09-05 群英技术资讯 1509 次浏览
今天这篇给大家分享的知识是“pandas创建series有哪些方法,常见操作怎样实现”,小编觉得挺不错的,对大家学习或是工作可能会有所帮助,对此分享发大家做个参考,希望这篇“pandas创建series有哪些方法,常见操作怎样实现”文章能帮助大家解决问题。print("====创建series方法一===")
dic={"a":1,"b":2,"c":3,"4":4}
s=pd.Series(dic)
print(s)
由字典创建,字典的key就是index,values就是valuse
key肯定是字符串,假如values类型不止一个会怎么样? → dic = {‘a’:1 ,‘b’:‘hello’ , ‘c’:3, ‘4’:4, ‘5’:5}
由数组创建(一维数组)
arr=np.random.rand(5) s=pd.Series(arr) print(arr) print(s) #默认index是从0开始,步长为1的数字 s=pd.Series(arr,index=['a','b','c','d','e'],dtype=np.object) print(s)
由标量创建
s=pd.Series(10,index=range(4)) print(s)
使用
from pandas import Series
a. 常规创建
>>> obj = Series([1,2,3], index=['A','B','C']) >>> obj A 1 B 2 C 3 dtype: int64
b. 根据字典创建
>>> obj = Series({'a':1,'b':2,'c':3})
>>> obj
a 1
b 2
c 3
dtype: int64
c. Series嵌套Series
>>> obj1 = Series([1,2,3],index=['a','b','c']) >>> obj2 = Series([4,5,6],index=['d','e','f']) >>> obj3 = Series([obj1, obj2],index=['name1', 'name2']) >>> obj3 name1 a 1 b 2 c 3 dtype: int64 name2 d 4 e 5 f 6 dtype: int64 dtype: object
>>> obj1 = Series([1,2,3],index=['a','b','c']) >>> obj1 a 1 b 2 c 3 dtype: int64 >>> obj1.append(Series([4,5],index=['d','e'])) a 1 b 2 c 3 d 4 e 5 dtype: int64
如果是嵌套的Series的追加
>>> obj1 = Series([1,2,3],index=['a','b','c'])
>>> obj1
a 1
b 2
c 3
dtype: int64
>>> obj1.drop('b')
a 1
c 3
dtype: int64
>>> obj1 = Series([1,2,3],index=['a','b','c']) >>> obj1 a 1 b 2 c 3 dtype: int64 >>> obj1.a = -1 >>> obj1['b'] = -2 >>> obj1 a -1 b -2 c 3 dtype: int64
>>> obj1 = Series([1,2,3],index=['a','b','c']) >>> obj1 a 1 b 2 c 3 dtype: int64 >>> print(obj1.a == 1) True
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
本篇文章给大家带来了关于Python的相关知识,每个 ndarray 都有一个关联的数据类型 (dtype) 对象。这个数据类型对象(dtype)告诉我们数组的布局。下面将通过示例详细讲讲NumPy的数据类型对象,需要的可以参考一下。
二分法检索介绍二分法检索(binary search)又称折半检索,二分法检索的基本思想是设字典中的元素从小到大有序地存放在数组(array)中,
python中argparse模块基础及使用步骤,下文有实例供大家参考,对大家了解操作过程或相关知识有一定的帮助,而且实用性强,希望这篇文章能帮助大家,下面我们一起来了解看看吧。
这篇文章给大家分享的是有关python实现webp图片格式转化的内容。小编觉得挺实用的,因此分享给大家做个参考,下文有具体的实例,接下来一起跟随小编看看吧。
这篇文章主要介绍了在Django中使用ElasticSearch,Elasticsearch是基于Lucene库的搜索引擎。它提供了具有HTTP Web界面和无模式JSON文档的分布式,多租户功能的全文本搜索引擎,下面详细内容,需要的朋友可以参考一下
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 ICP核准(ICP备案)粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008