• 技术文章 >Python技术 >Python基础教程

    python中filter()的多种筛选

    小妮浅浅小妮浅浅2021-08-03 10:02:45原创3204

    1、筛选指定的列,类似于花式索引

    df2.filter(items=['one','three'])
    """
     
    one three
    mouse 1 3
    rabbit 4 6
    """

    2、筛选以字母e结尾的列

    df2.filter(regex='e$', axis=1)
     
    """
     
    one three
    mouse 1 3
    rabbit 4 6
    """

    3、筛选以字母e结尾的行

    df2.filter(regex='e$',axis=0)
     
    """
     
    one two three
    mouse 1 2 3
    """

    4、筛选行索引中有bbi的行

    df2.filter(like='bbi',axis=0)
     
    """
     
    one two three
    rabbit 4 5 6
    """

    以上就是python中filter()的多种筛选,希望对大家有所帮助。更多Python学习指路:python基础教程

    本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

    专题推荐:python filter
    品易云
    上一篇:python marshmallow如何提供默认值 下一篇:python中apply和transform的比较

    相关文章推荐

    • Python如何实现时间累加的计算器• python中__init__ 和__new__的对比• python中__call__的触发执行• python中__enter__和__exit__的应用场景• python中类对象及类属性的介绍• python类实例化如何实现• python实例属性的查找顺序• python保护变量是什么• python私有方法的使用注意• python析构函数如何使用• python协程和线程的差异• python库如何实现对象的转换• python中marshmallow库如何使用• python dump方法的序列化• python使用required定义必填字段

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网