December 2018
Beginner to intermediate
682 pages
18h 1m
English
Within a SQL SELECT statement, the WHERE clause is very common and filters data. This recipe will write pandas code that is equivalent to a SQL query that selects a certain subset of the employee dataset.
Suppose we are given a task to find all the female employees that work in the police or fire departments that have a base salary between 80 and 120 thousand dollars. The following SQL statement would answer this query for us:
SELECT UNIQUE_ID, DEPARTMENT, GENDER, BASE_SALARYFROM EMPLOYEEWHERE DEPARTMENT IN ('Houston Police Department-HPD', 'Houston Fire Department (HFD)') AND GENDER = 'Female' AND BASE_SALARY BETWEEN 80000 AND 120000;