Series的创建

##数据分析汇总学习

https://blog.csdn.net/weixin_39778570/article/details/81157884

# 使用列表创建

 >>> import numpy as np
>>> import pandas as pd
>>> s1 = pd.Series([1,2,3,4])
>>> s1
0 1
1 2
2 3
3 4
dtype: int64
 # 查看s1的值和索引
>>> s1.values
array([1, 2, 3, 4], dtype=int64)
>>> s1.index
RangeIndex(start=0, stop=4, step=1) # 默认索引

# 使用数组创建

 >>> s2 = pd.Series(np.arange(10))
>>> s2
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
dtype: int32

# 使用字典创建

 >>> s3 = pd.Series({'':1, '':2, '':3})
>>> s3
1 1
2 2
3 3
dtype: int64
>>> s3.values
array([1, 2, 3], dtype=int64)
>>> s3.index
Index(['', '', ''], dtype='object')

Series的访问

 >>> s4 =  pd.Series([1,2,3,4], index = ['a','b','c','d'])
>>> s4
a 1
b 2
c 3
d 4
dtype: int64
>>> s4.values
array([1, 2, 3, 4], dtype=int64)
>>> s4.index
Index(['a', 'b', 'c', 'd'], dtype='object')
>>> s4['a'] # 访问索引为a的值
1
>>> s4[s4>2] #访问s4中值大于2的Series
c 3
d 4
dtype: int64

# Series与字典的转换

 >>> s4.to_dict()  # s4转换为字典
{'a': 1, 'b': 2, 'c': 3, 'd': 4} >>> s5 = pd.Series(s4.to_dict()) # 字典转换为Series
>>> s5
a 1
b 2
c 3
d 4
dtype: int64

# e索引无值补充为NaN

 >>> index_1 = ['a','b','c','d','e']
>>> s6 = pd.Series(s5, index = index_1)
>>> s6
a 1.0
b 2.0
c 3.0
d 4.0
e NaN # s5此处无值
dtype: float64

# NaN判断

 >>> pd.isnull(s6)
a False
b False
c False
d False
e True
dtype: bool
>>> pd.notnull(s6)
a True
b True
c True
d True
e False
dtype: bool

# 命名修改

 >>> s6.name = 'demo'   # s6的名字修改
>>> s6
a 1.0
b 2.0
c 3.0
d 4.0
e NaN
Name: demo, dtype: float64 >>> s6.index.name = 'demo_index' # s6的索引的名字的修改
>>> s6.index
Index(['a', 'b', 'c', 'd', 'e'], dtype='object', name='demo_index')

官网:http://pandas.pydata.org/pandas-docs/version/0.14.1/

如果还有问题未能得到解决,搜索887934385交流群,进入后下载资料工具安装包等。最后,感谢观看!

Pandas入门系列(一)-- Series的更多相关文章

  1. 利用Python进行数据分析——pandas入门

    利用Python进行数据分析--pandas入门 基于NumPy建立的 from pandas importSeries,DataFrame,import pandas as pd 一.两种数据结构 ...

  2. Python 数据处理库 pandas 入门教程

    Python 数据处理库 pandas 入门教程2018/04/17 · 工具与框架 · Pandas, Python 原文出处: 强波的技术博客 pandas是一个Python语言的软件包,在我们使 ...

  3. 利用python进行数据分析之pandas入门

    转自https://zhuanlan.zhihu.com/p/26100976 目录: 5.1 pandas 的数据结构介绍5.1.1 Series5.1.2 DataFrame5.1.3索引对象5. ...

  4. 利用python进行数据分析--pandas入门2

    随书练习,第五章  pandas入门2 # coding: utf-8 # In[1]: from pandas import Series,DataFrame import pandas as pd ...

  5. 利用python进行数据分析--pandas入门1

    随书练习,第五章  pandas入门1 # coding: utf-8 # In[1]: from pandas import Series, DataFrame # In[2]: import pa ...

  6. pandas 入门(3)

    from pandas import Series, DataFrame, Index import numpy as np # 层次化索引 对数据重塑和分组操作很有用 data = Series(n ...

  7. < 利用Python进行数据分析 - 第2版 > 第五章 pandas入门 读书笔记

    <利用Python进行数据分析·第2版>第五章 pandas入门--基础对象.操作.规则 python引用.浅拷贝.深拷贝 / 视图.副本 视图=引用 副本=浅拷贝/深拷贝 浅拷贝/深拷贝 ...

  8. 数据挖掘入门系列教程(四)之基于scikit-lean实现决策树

    目录 数据挖掘入门系列教程(四)之基于scikit-lean决策树处理Iris 加载数据集 数据特征 训练 随机森林 调参工程师 结尾 数据挖掘入门系列教程(四)之基于scikit-lean决策树处理 ...

  9. 数据挖掘入门系列教程(九)之基于sklearn的SVM使用

    目录 介绍 基于SVM对MINIST数据集进行分类 使用SVM SVM分析垃圾邮件 加载数据集 分词 构建词云 构建数据集 进行训练 交叉验证 炼丹术 总结 参考 介绍 在上一篇博客:数据挖掘入门系列 ...

随机推荐

  1. ORA-27090: Unable to reserve kernel resources for asynchronous disk I/O

    2019-08-19T09:27:33.225584+08:00Slave encountered ORA-27090 exception during crash recoveryRecovery ...

  2. idea git提交代码步骤

    这位兄台已经写的很清楚了... 我这里直接给你们链接把... https://blog.csdn.net/u013452337/article/details/79956604 Git 初次提交,以及 ...

  3. 使用shell脚本查看数据库负载情况

    原创 Oracle 作者:jeanron100 时间:2014-05-23 08:56:26  8912  2 平时在查看数据库的问题时,会有种迷茫的感觉,如果没有任何人反馈问题,基本上没有主动查找问 ...

  4. 洛谷 SP263 Period

    洛谷 SP263 Period 题目描述 For each prefix of a given string S* with N* characters (each character has an ...

  5. office2019专业版激活秘钥 激活码

    office2019专业版激活码 激活秘钥 2019年5月更新 [Key]:F4QWT-NMMKH-XPTV9-W9HFB-B4JCQ [剩余次数:900000+] office2019激活 产品秘钥 ...

  6. DBCC TRACEON - 跟踪标志 (Transact-SQL)

    跟踪标志用于设置特定服务器特征或更改特定行为. 例如,跟踪标志 3226 是一种常用的启动跟踪标志,可取消显示错误日志中的成功备份消息. 跟踪标志经常用于诊断性能问题或调试存储过程或复杂的计算机系统, ...

  7. linux命令--查找与帮助

    一.搜寻命令 1.whereis命令 whereis是搜索系统命令的命令,也就是说,whereis 命令不能搜索普通文件, 而只能搜索系统命令. 命令名称:whereis 英文原意:locate th ...

  8. Java描述设计模式(04):抽象工厂模式

    本文源码:GitHub·点这里 || GitEE·点这里 一.抽象工厂模式 1.生活场景 汽车生产根据用户选择的汽车类型,指定不同的工厂进行生产,选择红旗轿车,就要使用中国工厂,选择奥迪轿车,就要使用 ...

  9. Flutter竟然发布了1.5版本!!!!

    2018年2月,Flutter推出了第一个Beta版本,在2018年12月5日,Flutter1.0版本发布,当时用了用觉得这个东西非常好用,对于当时被RN搞的头皮发麻的我来说简直是看到了曙光.而在昨 ...

  10. Nginx安装及配置反向代理

    本片博客记录在ubuntu16下安装nginx,以及如何实现负载均衡 安装nginx 如果是新机器,安装相关依赖环境 sudo apt install build-essential sudo apt ...