ix和loc、iloc函数都是用来获取某一行或者某一列数据的。

请看如下案例:

import pandas as pd
data = [[1,2,3],[4,5,6],[7,8,9]]
rows = ['row1','row2','row3']#行标签
columns = ['col1','col2','col3']#列标签
df = pd.DataFrame(data, index=rows, columns=columns)
print df

运行结果:

      col1  col2  col3
row1     1     2     3
row2     4     5     6
row3     7     8     9

1.loc函数

官网解释

Purely label-location based indexer for selection by label.

.loc[] is primarily label based, but may also be used with a boolean array.

完全基于标签位置的索引器,所谓标签位置就是上面定义的'row1','row2'。

因此使用loc函数的时候,如果传入的不是标签而是下标将会导致如下错误:

TypeError: cannot do label indexing on <class 'pandas.core.indexes.base.Index'> with these indexers [1] of <type 'int'>

使用方法(row1就是行标签)

print df.loc['row1']

运行结果:

col1    1
col2    2
col3    3
Name: row1, dtype: int64

2.iloc函数

官网解释

Purely integer-location based indexing for selection by position.

.iloc[] is primarily integer position based (from 0 to length-1 of the axis), but may also be used with a boolean array.

完全基于行号的索引器,所谓行号就是第0、1、2行。

因此使用iloc函数的时候,如果传入的不是行号而是标签将会导致如下错误:

TypeError: cannot do positional indexing on <class 'pandas.core.indexes.base.Index'> with these indexers [row1] of <type 'str'>

使用方法(0就是行号)

print df.iloc[0]

运行结果:

col1    1
col2    2
col3    3
Name: row1, dtype: int64

3.ix函数

官网解释

A primarily label-location based indexer, with integer position fallback.

.ix[] supports mixed integer and label based access. It is primarily label based, but will fall back to integer positional access unless the corresponding axis is of integer type.

支持标签和行号混合的索引器,既可以通过标签也可以通过行号,还可以组合在一起(这个函数已经过期,建议使用上面两个函数替代

由于loc和iloc已经可以完成ix函数的工作,因此在后面ix函数有可能被移除,当前第一次运行ix函数的时候会有如下警告

 DeprecationWarning:
.ix is deprecated. Please use
.loc for label based indexing or
.iloc for positional indexing

使用方法(loc和iloc的结合)

print df.ix[0]

print df.ix['row1']

print df.ix['row1',‘col1’]

print df.ix['row1',0]

运行结果:

col1    1
col2    2
col3    3
Name: row1, dtype: int64
col1    1
col2    2
col3    3
Name: row1, dtype: int64
1
1

Pandas警告:DeprecationWarning: .ix is deprecated.(ix、loc、iloc的区别)相关推荐

  1. python中loc什么意思_python pandas 中 loc iloc 用法区别

    转自:https://blog.csdn.net/qq_21840201/article/details/80725433 ### 随机生DataFrame 类型数据 import pandas as ...

  2. pandas loc iloc ix用法详解

    1.什么是label pandas处理数据时,我们会经常看到dataframe结构使用loc, iloc, ix等方法.那么这些方法到底有啥区别,下面我们来进行详细分析. 首先我们先明确一点,这几个方 ...

  3. DeprecationWarning: NEAREST is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampl

    消除警告 DeprecationWarning: NEAREST is deprecated and will be removed in Pillow 10 (2023-07-01). Use Re ...

  4. pandas之loc iloc ix

    首先,介绍这三种方法的概述: loc: loc gets rows (or columns) with particular labels from the index. loc从索引中获取具有特定标 ...

  5. python dataframe loc函数_详解pandas DataFrame的查询方法(loc,iloc,at,iat,ix的用法和区别)...

    在操作DataFrame时,肯定会经常用到loc,iloc,at等函数,各个函数看起来差不多,但是还是有很多区别的,我们一起来看下吧. 首先,还是列出一个我们用的DataFrame,注意index一列 ...

  6. 2017.06.15-2016.06.18回顾 loc/iloc/ix dataframe相关 oracle无自增去重 correl

    上周最后阶段比较忙,主要是忙jd的数据测试的事情还有就是各种新产品的事情,下面回顾一下这段时间的工作. 1.上周四快下班的时候开了一个新产品的会,初步确定了风控策略,但是接近下班的时候又告诉我另外一个 ...

  7. python iloc iat_DataFrame的查询方法(loc,iloc,at,iat,ix的用法和区别)

    在操作DataFrame时,肯定会经常用到loc,iloc,at等函数,各个函数看起来差不多,但是还是有很多区别的,我们一起来看下吧. 首先,还是列出一个我们用的DataFrame,注意index一列 ...

  8. 【DeprecationWarning: BICUBIC is deprecated and will be removed in Pillow 10 (2023-07-01).的解决方案】

    DeprecationWarning: BICUBIC is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampl ...

  9. DeprecationWarning: LANCZOS is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampl

    DeprecationWarning: LANCZOS is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampl ...

最新文章

  1. 【NLP】Task5:神经网络基础
  2. 开始学java咯!~~~
  3. pt-osc原理、限制、及与原生online-ddl比较
  4. cifar10 c语言,Python3读取深度学习CIFAR-10数据集出现的若干问题解决
  5. lseek、stat、access、chmod、strtol、truncate、unlink
  6. 【演讲实录】下一代企业级应用架构管理体系
  7. Django笔记:ORM模型
  8. 基于matlab的升压斩波实验,升降压斩波电路matlab仿真
  9. hl3150cdn打印不了照片_揭秘:薇娅力荐国产品牌极印,照片打印机爆卖的秘密
  10. 解析腾讯云游戏多媒体引擎GME技术方案
  11. Cisco路由器配置命令
  12. 有什么方法可以将WMV格式转换成MP4格式
  13. 理论力学知识要点归纳(三)
  14. 学习Java的你知道什么是程序思维?
  15. 人工智能的快速发展,对我们的不利影响有哪些?
  16. 微博运营怎么做才能吸引更多的粉丝?
  17. 中煤哈密智能汽车电子衡系统过磅流程
  18. 保卫萝卜迅玩版53关php,2018微信保卫萝卜迅玩版第50关攻略
  19. 9月20日.周日 第一场正式的比赛:2020年CCPC网络赛
  20. 数据上报--应用进程通过CGI与html交互

热门文章

  1. 801冠号大全及桃花荧光
  2. Chest X-Ray Images (Pneumonia)(胸部X光片(肺炎)相关数据集)
  3. Sun Solaris
  4. 试题六(java+设计模式)
  5. [论文翻译]Pruning and Quantization for Deep Neural Network Acceleration: A Survey
  6. 第一个实训项目(2)
  7. java IO流---字符流
  8. 大小写金额转换(电子表格大小写金额转换)
  9. 计算机网络安全的目标,网络安全工作目标有哪些
  10. 计算机毕业设计Java房屋合租系统(源码+系统+mysql数据库+lW文档)