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


Companies using this Recipe
1 employee of Infosys
1 employee of eClerx
1 employee of Renovite Technologies
1 employee of Altimetrik
1 employee of Ericsson
1 employee of Wipro
1 employee of ANAC
1 employee of HCL Technologies
1 employee of CGI
1 employee of ICU Medical