You can also combine multiple logical statements, as long as each statement is in parentheses.
For instance, suppose we wanted to select all rows where the customer’s age was under 30 or the customer’s name was “Martha Jones”:
|Martha Jones||123 Main St.||234-567-8910||28|
|Rose Tyler||456 Maple Ave.||212-867-5309||22|
|Donna Noble||789 Broadway||949-123-4567||35|
|Amy Pond||98 West End Ave.||646-555-1234||29|
|Clara Oswald||54 Columbus Ave.||714-225-1957||31|
We could use the following code:
df[(df.age < 30) | (df.name == 'Martha Jones')]
| means “or” and
& means “and”.
You want to see how the number of clinic visits changed between March and April.
Create the variable
march_april, which contains the data from March and April. Do this using two logical statements combined using
|, which means “or”.