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

    数值筛选

    一、使用【】

    1. 单条件筛选

    最大逾期天数小于10

    due_days=10
    last_loan_df=last_loan_df[last_loan_df['max_due_days']<=due_days]

    2. 多条件筛选

    last_loan_df=last_loan_df[(last_loan_df['max_due_days']<=due_days )|(last_loan_df['score']>100) ]

    last_loan_df=last_loan_df[(last_loan_df['max_due_days']<=due_days )&(last_loan_df['score']>100) ]

    使用isin方法

    # 选择某列等于多个数值或者字符串

    last_loan_df[last_loan_df['custid'].isin([1,2,3,4,5])]

    字符串的模糊筛选

    一. .str.contains()

    # 选含有wqbin|bin的行

    df.loc[df['name'].str.contains('wqbin|bin']] 


    # 选不含wqbin或bin

    df.loc[df['name'].str.contains('wqbin|bin'] == False] 

    注意:这里只能使用或(|)不能用且(&)

    二. .str.startswith()

    # 选姓wang的行

    df.loc[df['name'].str.startswith('wang']] 

    完结!!

    其实本质上还是调用了loc

  • 相关阅读:
    password
    bzoj 1458: 士兵占领
    国家集训队2011 happiness
    cogs 2051. 王者之剑
    uva 10779 Collectors Problem
    [Jxoi2012]奇怪的道路
    天神下凡
    藏宝图
    黑红树
    愤怒的小鸟
  • 原文地址:https://www.cnblogs.com/wqbin/p/12967326.html
Copyright © 2011-2022 走看看