How to do it...

  1. Read in the employee data, assign the chosen departments, and import columns to variables:
>>> employee = pd.read_csv('data/employee.csv')>>> depts = ['Houston Police Department-HPD',             'Houston Fire Department (HFD)']>>> select_columns = ['UNIQUE_ID', 'DEPARTMENT',                      'GENDER', 'BASE_SALARY']
  1. Build the query string and execute the method:
>>> qs = "DEPARTMENT in @depts " \         "and GENDER == 'Female' " \         "and 80000 <= BASE_SALARY <= 120000"        >>> emp_filtered = employee.query(qs)>>> emp_filtered[select_columns].head()

Get Pandas Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.