How to select rows with multiple filters?
0

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