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. VUE组件 之 高德地图地址选择

    注:本文基于上一篇文章[ Vue-Cli 3.0 中配置高德地图] ,采用直接引入高德 SDK 的方式来使用高德地图api 一.效果图 二.组件要实现的功能 1. 如果有传入坐标点,则定位到坐标点 2 ...

  2. memcache和redis缓存对比及我为什么选择redis

    对比结论 1. 性能上: 性能上都很出色,具体到细节,由于Redis只使用单核,而Memcached可以使用多核,所以平均每一个核上Redis在存储小数据时比Memcached性能更高.而在100k以 ...

  3. [译]Vulkan教程(15)图形管道基础之RenderPass

    [译]Vulkan教程(15)图形管道基础之RenderPass Render passes Setup 设置 Before we can finish creating the pipeline, ...

  4. 2019年全国高校计算机能力挑战赛初赛C语言解答

    http://www.ncccu.org.cn 2019年全国高校计算机能力挑战赛分设大数据算法赛,人工智能算法赛,Office高级应用赛,程序设计赛4大赛项 C语言初赛解答 1:编程1 16.现有一 ...

  5. 【转载】【PAT】PAT甲级题型分类整理

    最短路径 Emergency (25)-PAT甲级真题(Dijkstra算法) Public Bike Management (30)-PAT甲级真题(Dijkstra + DFS) Travel P ...

  6. @Transactional注解失效

    一.特性 先来了解一下@Transactional注解事务的特性吧,可以更好排查问题 1.service类标签(一般不建议在接口上)上添加@Transactional,可以将整个类纳入spring事务 ...

  7. go面向对象之多态即接口(interface)

    Go 语言接口 Go 语言提供了另外一种数据类型即接口,它把所有的具有共性的方法定义在一起,任何其他类型只要实现了这些方法就是实现了这个接口. 实例 /* 定义接口 */ type interface ...

  8. git命令教程

    git教程笔记 Git是什么? Git是一个分布式版本控制系统 版本控制方式 集中式版本控制:从版本库中先取得最新的版本,改完之后再上传到版本库中,需要联网 分布式版本控制:每个合作者电脑上都有一个版 ...

  9. layui table 分页 序号始终从”1“开始解决方法

    在用Layui table 分页显示数据,用 type:"numbers" 进行显示序号有以下的问题 1.表格自带的分页,page:true 这种分页,在切换页面的时候序号可以正常 ...

  10. Linux相关集合

    本篇概述 Linux xshell6 连接 Hadoop 启动关闭 Linux xshell6 连接相关问题 首先,虚拟机 得先能通成网(具体教程可百度) 然后,进行 本机 ip 的查询(xshell ...