Filter Pandas Dataframe by multiple conditions

    0

    0

    Javier Pacheco

    The code uses the & operator to specify that the condition is logical AND. df2 is a dataframe that contains only columns that have both the conditions met.

    import pandas as pd
    
    df2 = df.loc[(df['column'] [condition1]) & (df['column2'] [condition2]) (...)]
    #[condition]: >=; <=; etc.
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.