---
url: /mosaic/examples/seattle-weather-pivot.md
---
# Seattle Weather Pivot

A DuckDB `PIVOT` query reshapes Seattle's daily weather observations into a cross-tab: one row per year, with a column counting the days of each weather type. The pivoted result is shown in a sortable `table` view. Click a column header to sort.

## Specification

```py \[Python]
import vgplot as vg

seattle_weather = vg.parquet("data/seattle-weather.parquet")
weatherByYear = vg.table(
    "PIVOT (SELECT *, year(date) AS year FROM seattle_weather) ON weather IN ('drizzle', 'fog', 'rain', 'snow', 'sun') USING count(*) GROUP BY year ORDER BY year"
)

view = vg.table_input(
    source=weatherByYear, align={"year": "left"}, width={"year": 80}, height=180
)

```
