pandas 索引选取和过滤(四)
建立Series
from pandas import Series,DataFrame
import numpy as np
import pandas as pd
obj=Series(np.arange(4),index=['a','b','c','d'])obj
Out[5]:
a 0
b 1
c 2
d 3
dtype: int32
选取
obj['b']
Out[6]: 1obj[1]
Out[7]: 1obj[3]
Out[8]: 3
obj[2:4]
Out[10]:
c 2
d 3
dtype: int32
obj[['b','a','d']]
Out[11]:
b 1
a 0
d 3
dtype: int32
obj[[1,3]]
Out[12]:
b 1
d 3
dtype: int32
obj[obj<2]
Out[13]:
a 0
b 1
dtype: int32
利用标签切片与普通python 切片不同,python是左闭右开区间[a,b),而标签切片是闭合区间[a,b]
In [14]: obj['b':'c']
Out[14]:
b 1
c 2
dtype: int32
obj['b','c']=5obj
Out[16]:
a 0
b 5
c 5
d 3
dtype: int32
DataFrame 选取
data=DataFrame(np.arange(16).reshape((4,4)),index=['ohio','colorado','utah','new york'],columns=['one','two','three','four'])
data
Out[18]: one two three four
ohio 0 1 2 3
colorado 4 5 6 7
utah 8 9 10 11
new york 12 13 14 15
data['two']
Out[19]:
ohio 1
colorado 5
utah 9
new york 13
Name: two, dtype: int32
data[['three','one']]
Out[20]: three one
ohio 2 0
colorado 6 4
utah 10 8
new york 14 12
data[:2]
Out[21]: one two three four
ohio 0 1 2 3
colorado 4 5 6 7
data[data['three']>5]
Out[22]: one two three four
colorado 4 5 6 7
utah 8 9 10 11
new york 12 13 14 15
data<5
Out[23]: one two three four
ohio True True True True
colorado True False False False
utah False False False False
new york False False False False
data[data<5]=0data
Out[26]: one two three four
ohio 0 0 0 0
colorado 0 5 6 7
utah 8 9 10 11
new york 12 13 14 15
ix的用法
data
Out[26]: one two three four
ohio 0 0 0 0
colorado 0 5 6 7
utah 8 9 10 11
new york 12 13 14 15
data.ix['colorado',['two','three']]
Out[27]:
two 5
three 6
Name: colorado, dtype: int32
data.ix[['colorado','utah'],[3,0,1]]
Out[29]: four one two
colorado 7 0 5
utah 11 8 9
data.ix[2]
Out[6]:
one 8
two 9
three 10
four 11
Name: utah, dtype: int32
data.ix[:'utah','two']
Out[9]:
ohio 1
colorado 5
utah 9
Name: two, dtype: int32
data.ix[data.three>5]
Out[13]: one two three four
colorado 4 5 6 7
utah 8 9 10 11
new york 12 13 14 15data.ix[data.three>5,:3]
Out[14]: one two three
colorado 4 5 6
utah 8 9 10
new york 12 13 14
pandas 索引选取和过滤(四)相关推荐
- python分组求和_Python学习笔记之pandas索引列、过滤、分组、求和功能示例
本文实例讲述了Python学习笔记之pandas索引列.过滤.分组.求和功能.分享给大家供大家参考,具体如下: 前面我们已经把519961(基金编码)这种基金的历史净值明细表html内容抓取到了本地, ...
- pandas获得指定行_如何用pandas实现选取特定索引的行
培训 的人在不断的增加, 今天小编就给大家分享一些关于 Python 开发的技能, 供喜欢 Python 开发的小伙伴学习, 下面就和小编一起来看一下如何用 pandas 实现选取特定索引的行吧. 如 ...
- pandas plot label_数据科学| 手把手教你用 pandas 索引、汇总、处理缺失数据
作者:Paul 编者按: pandas提供了很多常用的数学和统计方法,本文中将用十分详细的例子来具体进行介绍:另外在许多数据分析工作中,缺失数据是经常发生的,将会具体介绍如何处理缺失数据.本文十分详细 ...
- 字段缺失_数据科学| 手把手教你用 pandas 索引、汇总、处理缺失数据
作者:Paul 编者按: pandas提供了很多常用的数学和统计方法,本文中将用十分详细的例子来具体进行介绍:另外在许多数据分析工作中,缺失数据是经常发生的,将会具体介绍如何处理缺失数据.本文十分详细 ...
- pandas索引和选择
http://blog.csdn.net/pipisorry/article/details/18012125 索引Index Many of these methods or variants th ...
- pandas索引和选择数据
使用pandas索引和选择数据时,总是需要百度,因此决定对pandas.DataFrame中的索引和选择方法做个总结.所用的pandas版本号为0.20.1 pandas中有三种索引方法:.loc,. ...
- pandas索引复合索引dataframe数据、索引其中一个水平(level)的所有数据行(index all rows in a level)
pandas索引复合索引dataframe数据.索引其中一个水平(level)的所有数据行(index all rows in a level) 目录
- pandas索引复合索引dataframe数据、索引dataframe中指定行和指定列交叉格子的数据内容(getting a specific value)、使用元组tuple表达复合索引的指定行
pandas索引复合索引dataframe数据.索引dataframe中指定行和指定列交叉格子的数据内容(getting a specific value).使用元组tuple表达复合索引的指定行 目 ...
- pandas索引复合索引dataframe数据、索引其中一个水平(level)的所特定数据行、指定数据行(index a row of a level)、使用元组tuple表达复合索引的指定行
pandas索引复合索引dataframe数据.索引其中一个水平(level)的所特定数据行.指定数据行(index a row of a level).使用元组tuple表达复合索引的指定行 目录
最新文章
- 用matlab解公式,怎么用matlab解这个公式A MATLAB script that solves the differential e
- [C#][Newtonsoft.Json] Newtonsoft.Json 序列化时的一些其它用法
- Linux文件权限(3)
- 王侠对话农民丰收节交易会 万祥军:解读供销社服务平台
- SybaseIQ - utility_db介绍
- 如何解决大量样本标注问题
- memcache java client_Memcache的客户端连接系列(一) Java
- css广告跟随,jQuery网页右侧广告跟随滚动代码分享
- python 递归拷贝整个文件夹
- rpa打开浏览器_rpa.ie
- First flight, Let's do it!
- mysqlbinlog抽取某个表的信息
- CUDA memory
- mysql 速度评测_[评测]低配环境下,PostgresQL和Mysql读写性能简单对比(欢迎大家提出Mysql优化意见)...
- k线顶分型 python_顶底分型K线
- ctfshow-29-170
- 自定义圆形进度条 自定义倒计时进度条
- 按照jdk后cmd输入java -version命令查询jdk版本号无结果
- Xunsearch与Sphinx的预比较
- 鸿蒙系统学习 框架概述(一)
热门文章
- 数据结构-js实现栈和队列
- 一个很简短的 JS 生成器入门和用法参考
- 【转】 Java中的变量赋值和参数传递
- 顶级程序员的10条最佳实践
- 【Android】Vitamio 4.0 公测版发布(2013-05-28)
- zipimport.ZipImportError: can't decompress data; zlib not available
- Rhel6.0升级内核到3.0.4
- Oracle语句生成+存储过程测试工具发布:Easytran V0.1
- PAT甲级1009 Product of Polynomials:[C++题解]多项式乘法、高精度乘法
- SpringBoot+pagehelper分页之后还显示全部数据(分页不管用)的解决方案