未经同意请勿转载http://www.cnblogs.com/smallcrystal/

前文已经详细介绍DataFrame与Series两种数据结构,下面介绍DataFrame与Series的数据基本手段

一、pandas两种数据结构的index是不可修改的,pandas对象的一个重要方法是reindex

>>> f

lie     pop state  year

suoyin

a       1.5  ohio  2000

b       1.3  ohio  2001

c       1.7  ohio  2002

d       2.0   nev  2003

e       3.5   nev  2004

>>> f.reindex(list('bcadef'))

lie     pop state    year

suoyin

b       1.3  ohio  2001.0

c       1.7  ohio  2002.0

a       1.5  ohio  2000.0

d       2.0   nev  2003.0

e       3.5   nev  2004.0

f       NaN   NaN     NaN

>>> f.reindex(list('bcadef'),fill_value=0)#缺失值用0填充

lie     pop state  year

suoyin

b       1.3  ohio  2001

c       1.7  ohio  2002

a       1.5  ohio  2000

d       2.0   nev  2003

e       3.5   nev  2004

f       0.0     0     0

#method选项对缺失值所插值处理,ffill/pad:前向填充值;bfill/backfill:后向填充值

>>> f.reindex(list('bcadef'),method='ffill')

lie     pop state  year

suoyin

b       1.3  ohio  2001

c       1.7  ohio  2002

a       1.5  ohio  2000

d       2.0   nev  2003

e       3.5   nev  2004

f       3.5   nev  2004

#DataFrame数据格式,reindex不仅可以修改行索引,也可以修改列。

>>> f.reindex(columns=['pop','year','state','add'])

lie     pop  year state  add

suoyin

a       1.5  2000  ohio  NaN

b       1.3  2001  ohio  NaN

c       1.7  2002  ohio  NaN

d       2.0  2003   nev  NaN

e       3.5  2004   nev  NaN

最新文章

  1. 我的MYSQL学习心得(五) 运算符
  2. mysql中distinct的用法
  3. lockf
  4. web前端各大技术都能实现什么功能
  5. Homebrew安装及使用
  6. Httpclient请求数据
  7. [转]silverlight Datagrid 行上增加ToolTip
  8. java:String使用equals和==比较的区别
  9. 烂泥:【解决】Ubuntu下使用SSH连接centos系统很慢
  10. OpenJudge 7624 山区建小学
  11. sqlserver 保留小数方法
  12. Ubuntu下将Sublime Text设置为默认编辑器
  13. 第二种方式读取并显示HDFS中的内容
  14. The performance between the 'normal' operation and the 'shift' operation.
  15. python 10道面试陷阱题目
  16. Redis docker安装和主要功能
  17. (网页)a标签下载
  18. HDU 6166 Senior Pan(k点中最小两点间距离)题解
  19. 解决springmvc中使用redirect跳转后https变为http
  20. Linux常用命令2(远程文件下载+查看文件内容)

热门文章

  1. 如何正确学习web前端流程以及如何找工作
  2. IP自动切换脚本
  3. (十二)MySQL逻辑备份mysqldump
  4. CF 1006C Three Parts of the Array【双指针/前缀和/后缀和/二分】
  5. 洛谷——P2117 小Z的矩阵
  6. 揭秘响应式web设计
  7. 中文名: 交通事故责任认定, 英文名称: Traffic accident responsibility identification
  8. 杭电oj 1000
  9. python3开发进阶-Web框架的前奏
  10. @requestBody注解的使用(上)