摘自:http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.loc.html

具体用法,假设数据源为:

>>> df = pd.DataFrame([[1, 2], [4, 5], [7, 8]],
... index=['cobra', 'viper', 'sidewinder'],
... columns=['max_speed', 'shield'])
>>> df
max_speed shield
cobra 1 2
viper 4 5
sidewinder 7 8 用法示例:
1)单独标签,返回的是一个Series
2) 内嵌List,返回一个DataFrame

3)Single label for row and column,注意,先索引,再列名
4)多个索引加列名
5)用布尔值:针对行进行过滤。False表示不取这一行。True表示取出这一行

6)条件判断

其中,

7)设置值:选中某些值;整行;整列

更多用法,请看官方文档

 
 
 
 

 

Pandas中Loc用法总结的更多相关文章

  1. python pandas 中 loc & iloc 用法区别

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

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

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

  3. pandas中Loc vs. iloc vs. ix vs. at vs. iat?

    loc: only work on indexiloc: work on positionix: You can get data from dataframe without it being in ...

  4. pandas中loc-iloc-ix的使用

    转自:https://www.jianshu.com/p/d6a9845a0a34 Pandas中loc,iloc,ix的使用 使用 iloc 从DataFrame中筛选数据 iloc 是基于“位置” ...

  5. pandas-03 DataFrame()中的iloc和loc用法

    pandas-03 DataFrame()中的iloc和loc用法 简单的说: iloc,即index locate 用index索引进行定位,所以参数是整型,如:df.iloc[10:20, 3:5 ...

  6. Pandas:loc iloc ix用法

    参考:Pandas中关于 loc \ iloc \ ix 用法的理解 相同点 使用形式都是 df.xxx[ para1 , para2 ] #xxx表示loc iloc ix#df表示一个DataFr ...

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

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

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

    pandas中df.ix, df.loc, df.iloc 的使用场景以及区别: https://stackoverflow.com/questions/31593201/pandas-iloc-vs ...

  9. Pandas 数据处理 | Datetime 在 Pandas 中的一些用法!

    Datatime 是 Python 中一种时间数据类型,对于不同时间格式之间的转换是比较方便的,而在 Pandas 中也同样支持 DataTime 数据机制,可以借助它实现许多有用的功能,例如 1,函 ...

随机推荐

  1. Including R code in perl

    #example: use Statistics::R;#use R in perlmy $R = Statistics::R->new() ;$R->startR ;$R->sen ...

  2. django_视图层_便捷工具

    便捷工具 render(request, template_name, context=None, content_type=None, status=None, using=None) 将给定的模板 ...

  3. ROS * 了解学习urdf的内容格式及编写

    <?xml version="1.0" ?> 声明文件使用xml描述 <robot name="robot_name">定义这是一个机器 ...

  4. vue cli3.0配制axios代理

    今天学习时,想访问网易新闻接口,结果显而易见,因为跨域被浏览器拒绝了. 去网上找一下结果一开始找到的是2.x版本的配置,生硬的放进去,给我各种报错.编译阶段就炸了.浪费好多时间 再按3.0版本去搜索才 ...

  5. 《DSP using MATLAB》Problem 7.15

    用Kaiser窗方法设计一个台阶状滤波器. 代码: %% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...

  6. JavaScript作用域(第七天)

    我们都知道js代码是由自上而下的执行,但我们来看看下面的代码: test(); function test(){ console.log("hello world"); }; 如果 ...

  7. Linux安装MySQL_5.6

    E&T: CentOS_7.4 64位; mysql-5.6.42-linux-glibc2.12-x86_64.tar; Xftp5; Xshell5; P1.下载Linux环境下的MySQ ...

  8. maven 灵活构建

    灵活构建 项目的构建根据不同的情况可能需要有一定的差异,比如编译级别.依赖.打包的属性文件等在不同的运行环境中可能需要有不同的值.为了实现灵活构建,Maven内置了三个特性: 属性:在POM中通过${ ...

  9. C# 每个字节接受 处理串口数据 的方法

      /// <summary> /// 向串口发送信息,有返回值 /// </summary> /// <param name="serialPort" ...

  10. rust

    books--------------Rust 中文教程 RustPrimer http://wiki.jikexueyuan.com/project/rust-primer/any/any.html ...