pandas中df.ix, df.loc, df.iloc 的使用场景以及区别
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 的使用场景以及区别的更多相关文章
- pandas常用操作详解——.loc与.iloc函数的使用及区别
loc与iloc功能介绍:数据切片.通过索引来提取数据集中相应的行数据or列数据(可以是多行or多列) 总结: 不同:1. loc函数通过调用index名称的具体值来取数据2. iloc函数通过行序号 ...
- pandas中DataFrame的ix,loc,iloc索引方式的异同
pandas中DataFrame的ix,loc,iloc索引方式的异同 1.loc: 按照标签索引,范围包括start和end 2.iloc: 在位置上进行索引,不包括end 3.ix: 先在inde ...
- Pandas中loc,iloc与直接切片的区别
最近使用pandas,一直搞不清楚其中几种切片方法的区别,今天专门看了一下. 0. 把Series的行index或Dataframe的列名直接当做属性来索引. 如: s.index_name df.c ...
- python库学习笔记——Pandas数据索引:ix、loc、iloc区别
Different Choices for Indexing 1. loc--通过行标签索引行数据 1.1 loc[1]表示索引的是第1行(index 是整数) import pandas as pd ...
- Pandas——ix 与 loc 与 iloc 与 icol 的区别
来自:https://blog.csdn.net/xw_classmate/article/details/51333646 来自:https://blog.csdn.net/chenKFKevin/ ...
- python数据分析之pandas数据选取:df[] df.loc[] df.iloc[] df.ix[] df.at[] df.iat[]
1 引言 Pandas是作为Python数据分析著名的工具包,提供了多种数据选取的方法,方便实用.本文主要介绍Pandas的几种数据选取的方法. Pandas中,数据主要保存为Dataframe和Se ...
- Spark与Pandas中DataFrame对比
Pandas Spark 工作方式 单机single machine tool,没有并行机制parallelism不支持Hadoop,处理大量数据有瓶颈 分布式并行计算框架,内建并行机制paral ...
- Spark与Pandas中DataFrame对比(详细)
Pandas Spark 工作方式 单机single machine tool,没有并行机制parallelism不支持Hadoop,处理大量数据有瓶颈 分布式并行计算框架,内建并行机制paral ...
- pandas中DataFrame使用
切片选择 #显示第一行数据print(df.head(1)) #显示倒数三行数据 print(df.tail(3)) loc df.loc[row_index,col_index] 注意loc是根 ...
随机推荐
- Nginx HTTP反向代理基础配置
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #erro ...
- RadioButton控件选中、取消
js: var flag = true; function chkRadio(id) { id.checked = flag; flag = !flag; } aspx.cs: this.rbtKey ...
- PHP使用http_build_query()构造URL字符串的方法
http_build_query http_build_query -- 生成 url-encoded 之后的请求字符串描述string http_build_query ( array formda ...
- 实现stack 加上·getMin功能 时间复杂度为O(n)
package com.hzins.suanfa; import java.util.Stack; /** * 实现stack 加上·getMin功能 时间复杂度为O(n) * @author Adm ...
- codeforces 622B B. The Time
B. The Time time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- Python语言及其应用 第2章
- 移植memtester到android平台
硬件搭建起来能进入系统,首要就是测试内存的稳定性,需要一款内存测试工具. 一般都是选择memtester这款linux软件,下载地址如下:http://pyropus.ca/software/memt ...
- 开启现有android项目
开启工程 在屏幕上方的选单列上,选择「File->New->Project」, 会弹出「New Project」对话视窗.Eclipse 是通用的编辑环境,可根据你所安装的不同扩充套件而支 ...
- android开发中 解决服务器端解析MySql数据时中文显示乱码的情况
首先,还是确认自己MySql账户和密码 1.示例 账户:root 密码:123456 有三个字段 分别是_id .username(插入有中文数据).password 1)首先我们知道 ...
- select元素选择时间以及jQuery对select的属性操作
<select class="input04" id="1" name="in_class1" onchange="setc ...