1、简单筛选

>>> dates = pd.date_range('', periods=6)
>>> df = pd.DataFrame(np.arange(24).reshape((6,4)),index=dates, columns=['A','B','C','D'])
>>> print(df)
A B C D
2013-01-01 0 1 2 3
2013-01-02 4 5 6 7
2013-01-03 8 9 10 11
2013-01-04 12 13 14 15
2013-01-05 16 17 18 19
2013-01-06 20 21 22 23 >>> print(df['A'])
2013-01-01 0
2013-01-02 4
2013-01-03 8
2013-01-04 12
2013-01-05 16
2013-01-06 20
Freq: D, Name: A, dtype: int32
>>> print(df.A)
2013-01-01 0
2013-01-02 4
2013-01-03 8
2013-01-04 12
2013-01-05 16
2013-01-06 20
Freq: D, Name: A, dtype: int32 #选择跨越多行或多列
>>> print(df[0:3])
A B C D
2013-01-01 0 1 2 3
2013-01-02 4 5 6 7
2013-01-03 8 9 10 11
>>> print(df['':''])
A B C D
2013-01-02 4 5 6 7
2013-01-03 8 9 10 11
2013-01-04 12 13 14 15
#如果df[3:3]将会是一个空对象。后者选择20130102到20130104标签之间的数据,并且包括这两个标签。

2、根据标签loc筛选

通过标签名字选择某一行数据, 或者通过选择某行或者所有行:代表所有行)然后选其中某一列或几列数据

>>> print(df.loc[''])
A 4
B 5
C 6
D 7
Name: 2013-01-02 00:00:00, dtype: int32 >>> print(df.loc[:,['A','B']])
A B
2013-01-01 0 1
2013-01-02 4 5
2013-01-03 8 9
2013-01-04 12 13
2013-01-05 16 17
2013-01-06 20 21 >>> print(df.loc['',['A','B']])
A 4
B 5
Name: 2013-01-02 00:00:00, dtype: int32

3、根据序列iloc

通过位置选择在不同情况下所需要的数据例如选某一个,连续选或者跨行选等操作。

>>> print(df.iloc[3,1])
13
>>> print(df.iloc[3:5,1:3])
B C
2013-01-04 13 14
2013-01-05 17 18
>>> print(df.iloc[[1,3,5],1:3])
B C
2013-01-02 5 6
2013-01-04 13 14
2013-01-06 21 22

4、混合loc、iloc两种的ix

>>> print(df.ix[:3,['A','C']])
A C
2013-01-01 0 2
2013-01-02 4 6
2013-01-03 8 10

5、通过判断的筛选

即可以采用判断指令 (Boolean indexing) 进行选择. 我们可以约束某项条件然后选择出当前所有数据.。

>>> print(df[df.A>8])
A B C D
2013-01-04 12 13 14 15
2013-01-05 16 17 18 19
2013-01-06 20 21 22 23

Pandas选择数据的更多相关文章

  1. pandas选择数据-【老鱼学pandas】

    选择列 根据列名来选择某列的数据 import pandas as pd import numpy as np dates = pd.date_range("2017-01-08" ...

  2. Panda的学习之路(2)——pandas选择数据

    首先定义panda dates=pd.date_range(',periods=6) # print(dates) df=pd.DataFrame(np.arange(24).reshape(6,4) ...

  3. 【转】Pandas学习笔记(二)选择数据

    Pandas学习笔记系列: Pandas学习笔记(一)基本介绍 Pandas学习笔记(二)选择数据 Pandas学习笔记(三)修改&添加值 Pandas学习笔记(四)处理丢失值 Pandas学 ...

  4. pandas之数据选择

    pandas中有三种索引方法:.loc,.iloc和[],注意:.ix的用法在0.20.0中已经不建议使用了 import pandas as pd import numpy as np In [5] ...

  5. pandas 学习 第14篇:索引和选择数据

    数据框和序列结构中都有轴标签,轴标签的信息存储在Index对象中,轴标签的最重要的作用是: 唯一标识数据,用于定位数据 用于数据对齐 获取和设置数据集的子集. 本文重点关注如何对序列(Series)和 ...

  6. 【转载】使用Pandas对数据进行筛选和排序

    使用Pandas对数据进行筛选和排序 本文转载自:蓝鲸的网站分析笔记 原文链接:使用Pandas对数据进行筛选和排序 目录: sort() 对单列数据进行排序 对多列数据进行排序 获取金额最小前10项 ...

  7. 【转载】使用Pandas创建数据透视表

    使用Pandas创建数据透视表 本文转载自:蓝鲸的网站分析笔记 原文链接:使用Pandas创建数据透视表 目录 pandas.pivot_table() 创建简单的数据透视表 增加一个行维度(inde ...

  8. Python 数据分析 - 索引和选择数据

    loc,iloc,ix三者间的区别和联系 loc .loc is primarily label based, but may also be used with a boolean array. 就 ...

  9. 基于pandas进行数据预处理

    很久没用pandas,有些有点忘了,转载一个比较完整的利用pandas进行数据预处理的博文:https://blog.csdn.net/u014400239/article/details/70846 ...

随机推荐

  1. JS计算滚动条的宽度

    1.此方法检验成功 function getScrollbarWidth() { var oP = document.createElement('p'), styles = { width: '10 ...

  2. Python全栈开发 列表, 元组 数据类型知识运用及操作 range知识

    一.列表 1.什么是列表? 列表是一个可变类型,由  [ ] 表示,每一项元素用逗号隔开.列表能够装大量的数据,可以装对象的对象. 2.列表的索引和切片. 列表和字符串一样,也有索引和切片.只不过列表 ...

  3. JMeter学习(一)工具简单介绍(转载)

    转载自 http://www.cnblogs.com/yangxia-test 一.JMeter 介绍 Apache JMeter是100%纯JAVA桌面应用程序,被设计为用于测试客户端/服务端结构的 ...

  4. python学习day5 常量 运算符补充 流程控制基础

    1.常量 值不会改变的量 python中没有特别的语法定义常量,一般约定用全大写字母命名常量,比如圆周率pi 2.预算符补充 2.1算数运算符 print(10/3)除法运算 print(10//3) ...

  5. 修改nginx日志格式为json

    Nginx 日志默认为普通文本的格式 /Oct/::: +] "https://boss.zbt.com/finance/partner/create-account-gateway?id= ...

  6. beanstalkd 说明文档

    BEANSTALKD(1) BEANSTALKD(1) NAME beanstalkd - simple, fast work queue SYNOPSIS beanstalkd [options] ...

  7. js导出excel:前端当前数据的导出

    网上找的库文件,同样做了修改.在导出的时候,有时候数据第一列和最后一列可能是复选框和操作按钮,这个是我们不需要的,加了这个的过滤 //table2excel.js /* * jQuery table2 ...

  8. 22. Generate Parentheses (backTracking)

    Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...

  9. 不包含数据和字母的Webshell

        在做php20中的challenge5时学习到了php中可代替数字和字母的符号,悲剧的是这道题没做出来,目前先整理知识点吧555555555555     情况是:很多时候在敏感地方WAF会阻 ...

  10. React 入门实例教程【转】

    Any day will do. 哪一天都行 Are you kidding? 你在开玩笑吧! Congratulations! 祝贺你! I don’t mean it. 我不是故意的. 原文作者: ...