zoukankan      html  css  js  c++  java
  • DataFrame 按列筛选数据

    转自:https://blog.csdn.net/butterfly1107/article/details/82756902

    1.==与!=

    lc.loc[lc["grade"] == "B"].head()
    lc.loc[lc["grade"] != "B"].head()

    2.filter函数

    https://blog.csdn.net/weixin_44668131/article/details/99437698

    DataFrame.filter(items=None, like=None, regex=None, axis=None)
    #items对列进行筛选
    #regex表示用正则进行匹配
    #like进行筛选
    #axis=0表示对行操作,axis=1表示对列操作

    前三个参数是互斥的,只能出现一个。

    #items对列进行筛选,只保留items中的列
    df.filter(items=['one', 'three'])
             one  three
    teacher   1      3
    student   4      6
    #regex表示用正则进行匹配,对列名匹配正则表达式
    df.filter(regex='e$', axis=1)
             one  three
    teacher   1      3
    student   4      6
    #like进行筛选
    df.filter(like='ent', axis=0)
              one  two  three
    student    4    5    6

    3.isin()函数

    https://blog.csdn.net/weixin_39962394/article/details/112113656

    class_23 = titanic[titanic["Pclass"].isin([2, 3])]

    可根据列值筛选出一个子集。

  • 相关阅读:
    面向对象基础之类与对象
    常用模块(一)
    re模块与正则表达式
    初识模块
    函数进阶篇
    Spring + Mybatis 读写分离
    java包的所有类生成class
    Oralce数据库的优化
    Java 搜索引擎
    JAVA分布式架构的演进
  • 原文地址:https://www.cnblogs.com/BlueBlueSea/p/15362157.html
Copyright © 2011-2022 走看看