pandas Series 比 numpy array 要强大很多,体现在很多方面

首先, pandas Series 有一些方法,比如:

describe 方法可以给出 Series 的一些分析数据:

import pandas as pd

s =  pd.Series([1,2,3,4])
d = s.describe()
print(d)
count    4.000000
mean 2.500000
std 1.290994
min 1.000000
25% 1.750000
50% 2.500000
75% 3.250000
max 4.000000
dtype: float64

其次, pandas Series 和 numpy array  最大的区别是,  pandas Series有'索引'这一概念:

创建 pandas Series的时候,可以包含一个作为索引值的数组:

life = pd.Series([74.7, 75., 80., 72.8], index=['city1', 'city2', 'city3', 'city4'])
print(life)

其中 ['city1', 'city2', 'city3', 'city4']数组就是索引数组,会被作为 life   Series 的索引值:

city1    74.7
city2 75.0
city3 80.0
city4 72.8
dtype: float64

pandas Series 像是 list 与 dict 的结合, list 是有序的,按照位置0,1,2,3...来获取对应位置的元素, dict 是无序的,通过 key 来获取对应的元素, pandas Series 既有序,又有索引 key , 可以通过 key 来获取元素:

print(life['city1'])

# 结果 74.7

也可以通过位置索引来获取元素:

print(life[0])

# 结果 74.7

为了更好的区分位置索引和 key 索引, pandas Series 提供了两个方法:

print(life.loc['city1'])
print(life.iloc[0])

loc 传入 key 索引值, iloc 传入位置索引值.

最新文章

  1. js限制文本框只能输入数字方法小结
  2. 复制Eclipse工作空间设置
  3. 5月18日:top10面试算法-LRUcache的实现
  4. 配置Symfony2
  5. 【boost】使用装饰者模式改造boost::thread_group
  6. linux目录/术语/英文
  7. 《深入Java虚拟机学习笔记》- 第12章 整数运算
  8. NOI2014 动物园
  9. iOS之CAKeyframeAnimation关键帧动画详解
  10. PLSQL Developer Debug
  11. Index Full Scan vs Index Fast Full Scan-1103
  12. Relative与Absolute组合使用
  13. SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data错误的解决
  14. Alpha(10/10)
  15. [DevExpress使用随笔]之NavBarControl控件(一)【转】
  16. 爱快路由计费系统easyradius隆重发布,支持V2版本,欢迎大家测试使用
  17. <spark> ~/spark/conf/spark-default.conf 配置文件
  18. Flask中的before_request和after_request
  19. [转帖][Bash Shell] Shell学习笔记
  20. MySQL 5.6 GTID 原理以及使用

热门文章

  1. vs code 问题:preLaunchTask“build”已终止,退出代码为 1。解决办法
  2. 转:TCP/IP协议栈的基本工作原理
  3. 利用jquery修改href的部分字符
  4. 关于easyui的问答(来自百度问答)
  5. ThinkPHP学习(二)
  6. 【Spring】SpringMVC中浅析数据的传递方式
  7. C# 程序打包Release版本
  8. php 将秒数转换为时间(年、天、小时、分、秒)
  9. Java读取excel的示例
  10. android开发之interpolator的使用