pandas中df.ix, df.loc, df.iloc 的使用场景以及区别:

https://stackoverflow.com/questions/31593201/pandas-iloc-vs-ix-vs-loc-explanation

# Note: in pandas version 0.20.0 and above, ix is deprecated and the use of loc and iloc is encouraged instead.

# First, a recap:
● loc works on labels in the index.
● iloc works on the positions in the index (so it only takes integers).
● ix usually tries to behave like loc but falls back to behaving like iloc if the label is not in the index. # Combining position-based and label-based indexing
>>> df = pd.DataFrame(np.nan,
index=list('abcde'),
columns=['x','y','z', 8, 9])
>>> df
x y z 8 9
a NaN NaN NaN NaN NaN
b NaN NaN NaN NaN NaN
c NaN NaN NaN NaN NaN
d NaN NaN NaN NaN NaN
e NaN NaN NaN NaN NaN >>> df.ix[:'c', :4]
x y z 8
a NaN NaN NaN NaN
b NaN NaN NaN NaN
c NaN NaN NaN NaN >>> df.iloc[:df.index.get_loc('c') + 1, :4]
x y z 8
a NaN NaN NaN NaN
b NaN NaN NaN NaN
c NaN NaN NaN NaN # get_loc() is an index method meaning "get the position of the label in this index".
# Note that since slicing with iloc is exclusive of its endpoint, we must add 1 to this value if we want row 'c' as well

pandas中df.ix, df.loc, df.iloc 的使用场景以及区别的更多相关文章

  1. pandas常用操作详解——.loc与.iloc函数的使用及区别

    loc与iloc功能介绍:数据切片.通过索引来提取数据集中相应的行数据or列数据(可以是多行or多列) 总结: 不同:1. loc函数通过调用index名称的具体值来取数据2. iloc函数通过行序号 ...

  2. pandas中DataFrame的ix,loc,iloc索引方式的异同

    pandas中DataFrame的ix,loc,iloc索引方式的异同 1.loc: 按照标签索引,范围包括start和end 2.iloc: 在位置上进行索引,不包括end 3.ix: 先在inde ...

  3. Pandas中loc,iloc与直接切片的区别

    最近使用pandas,一直搞不清楚其中几种切片方法的区别,今天专门看了一下. 0. 把Series的行index或Dataframe的列名直接当做属性来索引. 如: s.index_name df.c ...

  4. python库学习笔记——Pandas数据索引:ix、loc、iloc区别

    Different Choices for Indexing 1. loc--通过行标签索引行数据 1.1 loc[1]表示索引的是第1行(index 是整数) import pandas as pd ...

  5. Pandas——ix 与 loc 与 iloc 与 icol 的区别

    来自:https://blog.csdn.net/xw_classmate/article/details/51333646 来自:https://blog.csdn.net/chenKFKevin/ ...

  6. python数据分析之pandas数据选取:df[] df.loc[] df.iloc[] df.ix[] df.at[] df.iat[]

    1 引言 Pandas是作为Python数据分析著名的工具包,提供了多种数据选取的方法,方便实用.本文主要介绍Pandas的几种数据选取的方法. Pandas中,数据主要保存为Dataframe和Se ...

  7. Spark与Pandas中DataFrame对比

      Pandas Spark 工作方式 单机single machine tool,没有并行机制parallelism不支持Hadoop,处理大量数据有瓶颈 分布式并行计算框架,内建并行机制paral ...

  8. Spark与Pandas中DataFrame对比(详细)

      Pandas Spark 工作方式 单机single machine tool,没有并行机制parallelism不支持Hadoop,处理大量数据有瓶颈 分布式并行计算框架,内建并行机制paral ...

  9. pandas中DataFrame使用

    切片选择 #显示第一行数据print(df.head(1)) #显示倒数三行数据 print(df.tail(3)) loc  df.loc[row_index,col_index]  注意loc是根 ...

随机推荐

  1. GIT使用[git remove untracked working file]

    使用GIT进行merge的时候, git merge --no-ff master 如果merge之后出现问题, 想进行回退, 可以使用 git reset --hard HEAD 来回退到最新的版本 ...

  2. Jquery实现动态导航栏和轮播导航栏

    动态导航栏和轮播导航栏的实现思想: 利用jquery技术的append()方法和bind()方法实现li标签的添加和点击事件绑定,在利用$getJSON(url,data,function)请求方法实 ...

  3. 宽度显示banner

    今天解决了一个以前解决不了的问题,所以就想找博客园记录一些笔记. ……以前也遇到过这种满屏banner不知道怎么做的问题,问老师老师也说不出个所以然,百度搜了好几条 也不太满意... 所以就开始尝试摸 ...

  4. Windows cmd findstr

    /********************************************************************************** * Windows cmd fi ...

  5. 使用WindowsAPI获取录音音频的方法

    这篇文章主要介绍了使用WindowsAPI获取录音音频的方法,非常实用的功能,需要的朋友可以参考下 本文实例介绍了使用winmm.h进行音频流的获取的方法,具体步骤如下: 一.首先需要包含以下引用对象 ...

  6. bzoj 1006: 神奇的国度 MCS

    题目大意: 弦图的最小染色. 题解: 裸题. #include <vector> #include <cstdio> #include <cstring> #inc ...

  7. openstackM版本安装

    部署期间常见问题:http://www.cnblogs.com/bfmq/p/6001233.html,问题跟对架构的理解永远比部署重要!你玩技术是绝对是要基于理论的 一.基本情况:物理设备:4台惠普 ...

  8. Linux系统主流架构一

    Linux系统主流架构一 随着IT运维的不断发展,尤其的Linux的飞速发展,越来越多的企业开始使用Linux操作系统,例如:Centos.Red Hat.Ubuntu.Fadora等等,成千上亿个网 ...

  9. php-fpm包的安装与配置

    实验环境:CentOS7 [root@~ localhost]#yum -y install php-fpm php-fpm包:用于将php运行于fpm模式 #在安装php-fpm时,一般同时安装如下 ...

  10. 拖动调整div布局大小

    一.需求 实现类似windows软件的那种,拖动调整两个div的大小 二.结果示例: 三.示例代码: https://github.com/CinYung/jQuery.divResizer.git