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. 苹果_公司开发者账号_注册Apple ID

    本文所有网站入口为developer.apple.com 注册Apple ID 注意事项:目前注册信息尽量用拼音或英文,姓名格式正确,记住安全问题,出生日期在18岁以上(小于18岁会出现Sorry,y ...

  2. 团队项目之Scrum5

    小组:BLACK PANDA 时间:2019.11.25   每天举行站立式会议 提供当天站立式会议照片一张 2 昨天已完成的工作 2 实现文章展示页面 完善后台的编辑功能接口 今天计划完成的工作 2 ...

  3. "(error during evaluation)" computed

    在vue-cli搭建的去哪网app项目中使用了  computed  计算属性 computed计算属性在chrome插件中的 vue devtools 插件中报错 应该显示出来 computed 属 ...

  4. 12.2 中的Data Guard Standby 密码文件自动同步 (Doc ID 2307365.1)

    Data Guard Standby Automatic Password file Synchronization in 12.2 (Doc ID 2307365.1) APPLIES TO: Or ...

  5. Java8特性

    java8特性 Oracle 公司于 2014 年 3 月 18 日发布 Java 8 ,它支持函数式编程,新的 JavaScript 引擎,新的日期 API,新的Stream API 等. 1.la ...

  6. Linux系统iptables与firewalld防火墙

    iptables iptables服务用于处理或过滤流量的策略条目(规则),多条规则可以组成一个规则链,而规则链则依据数据包处理位置的不同进行分类. 在进行路由选择前处理数据包(PREROUTING) ...

  7. Ubuntu16.04重装NVIDIA驱动

    Ubuntu系统 $ sudo apt update $ sudo apt upgrade 之后出现显卡驱动出现故障,nvidia-smi输出有错,检测不到相应的驱动.只好重装,记录一下,太多的教程根 ...

  8. ArrayList和LinkedList介绍

    java.util.ArrayList集合的数据存储结构是数组,且是多线程,元素增删慢,查找快, 由于日常使用开发大多数为查询数据,遍历数据,所以ArrayList是最常用的集合.上一节已写了. ja ...

  9. 【algo&ds】4.B树、字典树、红黑树、跳表

    上一节内容[algo&ds]4.树和二叉树.完全二叉树.满二叉树.二叉查找树.平衡二叉树.堆.哈夫曼树.散列表 7.B树 B树的应用可以参考另外一篇文章 8.字典树Trie Trie 树,也叫 ...

  10. python 读取ini 配置文件

    安装 pip install configparser 1 配置文件 config.ini: [MysqlDB]user=rootpasswd=123456sport=3306db_name=my_d ...