df.query multiple conditions code example

Example 1: select rows with multiple conditions pandas query

df.loc[(df['Salary_in_1000']>=100) & (df['Age']< 60) & (df['FT_Team'].str.startswith('S')),['Name','FT_Team']]

Example 2: or condition in pandas

df1 = df[(df.a != -1) & (df.b != -1)]

Example 3: or condition in pandas

df2 = df[(df.a != -1) | (df.b != -1)]

Example 4: select rows with multiple conditions pandas query

df.query('Salary_in_1000 >= 100 & Age < 60 & FT_Team.str.startswith("S").values')

Example 5: filter dataframe multiple conditions

# when you wrap conditions in parantheses, you give order
# you do those in brackets first before 'and'
# AND
movies[(movies.duration >= 200) & (movies.genre == 'Drama')]

Example 6: select rows with multiple conditions pandas query

df.loc[idx]