Recipe: How to select rows with multiple filters?
DATA MUNGING DATA CLEANING PYTHON

How to select rows with multiple filters?

This recipe helps you select rows with multiple filters
In [1]:
# How to select rows with multiple filters
def Snippet_108():
    print()
    print(format('How to select rows with multiple filters','*^82'))

    import warnings
    warnings.filterwarnings("ignore")

    # load libraries
    import pandas as pd

    # Create an example dataframe
    data = {'name': ['A', 'B', 'C', 'D', 'E'],
            'score': [1,2,3,4,5]}

    df = pd.DataFrame(data)
    print(); print(df)

    # Select rows of the dataframe where df.score is greater than 1 and less and 5
    df1 = df[(df['score'] > 1) & (df['score'] < 5)]
    print(); print(df1)

Snippet_108()
*********************How to select rows with multiple filters*********************

  name  score
0    A      1
1    B      2
2    C      3
3    D      4
4    E      5

  name  score
1    B      2
2    C      3
3    D      4


Stuck at work?
Can't find the recipe you are looking for. Let us know and we will find an expert to create the recipe for you. Click here
Companies using this Recipe
3 developers from Infosys
2 developers from HCL
1 developer from Archeplay Software
1 developer from Ericsson
1 developer from GAVS Technologies
1 developer from HvH
1 developer from Jed-i Technologies
1 developer from Mercy Hospital Chicago
1 developer from Waveinfosoft
1 developer from Accenture