July 2019
Beginner to intermediate
740 pages
16h 52m
English
Pandas provides a query() method so that we can easily write complicated filters instead of using a mask. The syntax is similar to the WHERE clause in a SQL statement. To illustrate this, let's query the weather data for all rows where the value of SNOW was greater than zero:
>>> snow_data = weather.query('datatype == "SNOW" and value > 0')>>> snow_data.head()
Each row is a snow observation for a given combination of date and station. Notice that the values vary quite a bit for January 4th—some stations received more snow than others:
| attributes | datatype | date | station | value | |
|---|---|---|---|---|---|
| 126 | ,,N, | SNOW | 2018-01-01T00:00:00 | GHCND:US1NYWC0019 | 25.0 |
| 722 | ,,N, | SNOW | 2018-01-04T00:00:00 | GHCND:US1NJBG0015 | 229.0 |
| 725 | ,,N, | SNOW | 2018-01-04T00:00:00 ... |
Read now
Unlock full access