学习笔记6—pandas中ix,loc,iloc有什么区别?
直接看例子:
>>> data = pd.Series(np.arange(10), index=[49,48,47,46,45, 1, 2, 3, 4, 5])
>>> data
49 0
48 1
47 2
46 3
45 4
1 5
2 6
3 7
4 8
5 9
dtype: int64
>>> data.iloc[:3]
49 0
48 1
47 2
dtype: int64
>>> data.loc[:3]
49 0
48 1
47 2
46 3
45 4
1 5
2 6
3 7
dtype: int64
>>> data.ix[:3]
49 0
48 1
47 2
46 3
45 4
1 5
2 6
3 7
dtype: int64
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
解析:
loc 在index的标签上进行索引,范围包括start和end.
iloc 在index的位置上进行索引,不包括end.
ix 先在index的标签上索引,索引不到就在index的位置上索引(如果index非全整数),不包括end.
>>> data.iloc[:6]
49 0
48 1
47 2
46 3
45 4
1 5
dtype: int64
>>> data.loc[:6]
KeyError: 6
>>> data.ix[:6] #因为index里面不包含标签6,index都是整数
KeyError: 6
>>> data= pd.Series(np.arange(10), index=['a','b','c','d','e', 1, 2, 3, 4, 5])
>>> data
a 0
b 1
c 2
d 3
e 4
1 5
2 6
3 7
4 8
5 9
dtype: int64
>>> data.ix[:6]
a 0
b 1
c 2
d 3
e 4
1 5
dtype: int64
>>> data.loc[:6]
TypeError: cannot do slice indexing
学习笔记6—pandas中ix,loc,iloc有什么区别?的更多相关文章
- Pandas中关于 loc \ iloc 用法的理解
转载至:https://blog.csdn.net/w_weiying/article/details/81411257 loc函数:通过行索引 "Index" 中的具体值来取行数 ...
- 学习笔记之pandas
Python Data Analysis Library — pandas: Python Data Analysis Library https://pandas.pydata.org/ panda ...
- 并发编程学习笔记(4)----jdk5中提供的原子类及Lock使用及原理
(1)jdk中原子类的使用: jdk5中提供了很多原子类,它会使变量的操作变成原子性的. 原子性:原子性指的是一个操作是不可中断的,即使是在多个线程一起操作的情况下,一个操作一旦开始,就不会被其他线程 ...
- [学习笔记] 在Eclipse中导入项目
参考前文:[学习笔记] 在Eclips 中导出项目 选择已经导出的文件: 导入之后,项目结构如下: 至此,完成.
- CockroachDB学习笔记——[译]CockroachDB中的SQL:映射表中数据到键值存储
CockroachDB学习笔记--[译]CockroachDB中的SQL:映射表中数据到键值存储 原文标题:SQL in CockroachDB: Mapping Table Data to Key- ...
- [学习笔记] 在Eclipse中导出可以直接运行的jar,依赖的jar中的类解压后放在运行jar中
前文: [学习笔记] 在Eclipse中导出可以直接运行的jar,依赖的jar打在jar包中 使用7z打开压缩包,查看所有依赖的jar都被解压以包名及class的方式存储在了运行jar中,此时jar的 ...
- [学习笔记] 在Eclipse中导出可以直接运行的jar,依赖的jar打在jar包中
本文需要参考前文: [学习笔记] 在Eclipse中导出可以直接运行的jar,依赖的jar在子目录中 上文是导出的运行的依赖jar被放在了子目录中,本文是将依赖jar放在可运行jar的本身,这样发布的 ...
- [学习笔记] 在Eclipse中导出可以直接运行的jar,依赖的jar在子目录中
工程创建可参考前文: [学习笔记] 在Eclipse中使用Hibernate,并创建第一个工程,数据库为Oracle XE 在工程上鼠标右键: 找到java 选择 Runable JAR file N ...
- Web安全学习笔记 SQL注入中
Web安全学习笔记 SQL注入中 繁枝插云欣 --ICML8 权限提升 数据库检测 绕过技巧 一.权限提升 1. UDF提权 UDF User Defined Function,用户自定义函数 是My ...
随机推荐
- java使用wait(),notify(),notifyAll()实现等待/通知机制
public class WaitNotify { static boolean flag=true; static Object lock=new Object(); static class Wa ...
- django F表达式、Q表达式、annotate、order_by
如下模型: class Book(models.Model): name = models.CharField(max_length=100) pages = models.IntegerField( ...
- fjwc2019 D4T1 循环流
#187. 「2019冬令营提高组」循环流 假的网络流,其实是O(1)算法 手画n个图后,你会发现只要分成几种情况讨论讨论就得了. 当$a==1$时显然不存在. 当$a!=1$时 如果$n==2$,显 ...
- Tree Implementation with Python
Tree Implementation with Python List of List 代码如下: def binary_tree(val): return [val, [], []] def in ...
- mtr 命令
mtr命令的使用: -r --report 以报告的方式发布监测的结果 -s 30 指定发送包的大小 这个随意 按照自己的需求 -i 10 设置icmp协议返回包的时间 -n no- ...
- Android Studio报错view is not constrained
在活动上面创建了两个按钮,在Design上看上去是两个按钮分开的,run一下,按钮就重合在一起了,而且一直报错,这个时候再去看一下Design,两个按钮重在一块,只显示一个按钮.如下图: button ...
- eMMC应用教程:关于RPMB的应用【转】
本文转载自:https://blog.csdn.net/youdianhai/article/details/51246379 RPMB的意思是Replay Protected Memory Bloc ...
- github帐户和仓库的创建
sign up is registration and sign in is logging in for "in" is to enter an existing account ...
- 【分布式事务】spring cloud集成lcn解决分布式事务
参考地址:https://blog.csdn.net/u010882691/article/details/82256587 参考地址:https://blog.csdn.net/oyh1203/ar ...
- Sample Classification Code of CIFAR-10 in Torch
Sample Classification Code of CIFAR-10 in Torch from: http://torch.ch/blog/2015/07/30/cifar.html req ...