Python学习(十三)——pandas函数库2
来源:互联网 发布:xshell连接linux 编辑:程序博客网 时间:2024/06/05 05:04
重新索引
创建一个适应新索引的新对象,该Series的reindex将会根据新索引进行重新排列。如果某个索引值不存在,就引入缺失值。
对于时间序列这样的有序数据,重新索引时可能需要做一些插值处理。method选项即可达到此目的。
1、重新索引
如,构造一个Series:
ser0=Series([101,202,303,404],index=['one','two','three','four'])print ser0
输出:
one 101two 202three 303four 404dtype: int64
进行重新索引:
ser1=ser0.reindex(['three','two','four','one'])print ser1
输出:
three 303two 202four 404one 101dtype: int64
2、对于新出现的索引,则引入缺失值:
ser1=ser0.reindex(['three','two','four','one','ten'])print ser1
输出:
three 303.0two 202.0four 404.0one 101.0ten NaNdtype: float64
3、未指定缺失值时默认填充为NaN,也可以通过fill_value指定填充值:
ser1=ser0.reindex(['three','two','four','one','ten'],fill_value=10)print ser1
输出:
three 303two 202four 404one 101ten 10dtype: int64
4、重新索引并通过method指定填充元素的方法
ser0=Series([101,202,303],index=[0,3,6])ser1=ser0.reindex(range(9),method='ffill')print ser1
输出:
0 1011 1012 1013 2024 2025 2026 3037 3038 303dtype: int64
‘ffill’代表如果该行的值为空,则用前一行
阅读全文
1 0
- Python学习(十三)——pandas函数库2
- Python学习(十二)——pandas函数库1
- 【C++】学习笔记二十三——字符函数库cctype
- Python——Pandas
- python——pandas
- python 学习笔记(十三)
- Python学习笔记(十三)
- python学习(二十三)
- 常用python——pandas
- python——pandas总结
- python——pandas应用
- python——pandas库
- python:pandas(2),基本功能
- python学习笔记(二)——Pandas十分钟入门
- pandas学习笔记2—透视表(pivot_table)详解
- Python:Pandas学习笔记(1)
- python学习笔记一(pandas入门)
- python学习笔记二(pandas基础)
- Longest Substring Without Repeating Characters 解决思路
- (C)顺序表实现集合运算
- 简单题两道(三分求极值)
- (CodeForces
- 剑指offer_数组---把数组排成最小的数
- Python学习(十三)——pandas函数库2
- Symmetric Tree
- 千寻穗C语言学习笔记 8.25 8.26(伪)
- 关于puppet脚本的一些笔记
- KMP算法
- Listener(监听器)
- 作用域public,protected,private的区别?以及不写时的区别?
- 一张图理清SpringMVC工作原理
- HDFS对象存储:Ozone的块异步删除服务