Five years of Beijing air quality with Arx

December 2, 2026

How much can you learn from a 2 MB CSV? Follow five years of hourly PM2.5 records from download to analysis to Parquet with Arx 1.33.0.

The Beijing air-quality CSV has a row for every hour from 2010 through 2014. Some hours have no PM2.5 reading, and a row count alone gives no hint of how many are missing. Before asking how much fine particulate matter was recorded, we need to know which hours actually have a measurement.

The dataset pairs PM2.5 readings from the U.S. embassy in Beijing with airport weather observations. We’ll open it in Arx, a statically typed language that uses LLVM to build native programs and Apache Arrow for columnar data. Beijing PM2.5, Song Chen (2015) · CC BY 4.0 · Arx 1.33.0 release notes

Start with the CSV

Install Arx 1.33.0 and download the original CSV. The examples need a native toolchain with Clang and a C++ compiler for Arrow. Installation and toolchain guide

python -m pip install arxlang==1.33.0
curl -fL -o beijing-pm25.csv \
  'https://archive.ics.uci.edu/ml/machine-learning-databases/00381/PRSA_data_2010.1.1-2014.12.31.csv'

Save the loader as readings.x next to the CSV. It names the input fields so we can refer to the original pm2.5 column as pm25 in Arx, and it keeps the four calendar fields with that measurement. The source uses NA for missing values. A 4 MiB read block lets type inference see decimal weather values that first appear late in the file. The reader validates the CSV before selecting the requested columns. CSV parsing guide

```
title: Load hourly Beijing PM2.5 readings
```

import read_csv from stdlib.csv


fn load_readings() -> dataframe[...]:
  return read_csv(
    "beijing-pm25.csv",
    header=false,
    skiprows=1,
    names=[
      "id", "year", "month", "day", "hour", "pm25", "dew_point",
      "temperature", "pressure", "wind_direction", "wind_speed",
      "snow_hours", "rain_hours",
    ],
    columns=["year", "month", "day", "hour", "pm25"],
    null_values=["NA"],
    block_size=4194304
  )

Count the hours that have a measurement

The CSV reader returns a DataFrame whose schema comes from the file. To work with a named Series, the code checks that the table has the expected names, types, and nullability. Save this as summary.x in the same directory.

```
title: Summarize the recorded PM2.5 concentrations
```

import load_readings from readings


fn main() -> i32:
  readings: auto = load_readings()
  table: auto = cast(readings, dataframe[
    year: i64 | none, month: i64 | none, day: i64 | none,
    hour: i64 | none, pm25: i64 | none
  ])
  pm25: auto = table.pm25
  count: i64 = series_count(pm25)
  assert count > 0
  print(count)
  print(table.nrows() - count)
  print(fill_null(series_mean(pm25), cast(0.0, f64)))
  print(fill_null(series_max(pm25), cast(0, i64)))
  return 0

Run arx run summary.x. Of the 43,824 hourly records, 41,757 contain a PM2.5 reading and 2,067 are missing it. The observed mean is about 98.61 µg/m³, and the maximum is 994 µg/m³. The mean and maximum skip nulls. A recorded zero still counts as a measurement.

The whole-period maximum answers one question. If you want to see which years had the highest recorded readings, the benchmark’s annual-peaks program slices the chronological Series into five calendar years and takes a maximum for each slice. It accounts for the extra day in 2012. The resulting peaks for 2010 through 2014 are 980, 595, 994, 886, and 671 µg/m³. Arx DataFrames and nullable Series · Annual peaks example

Share the selected columns as Parquet

Once the columns and missing values are accounted for, a colleague can use the same selection without repeating the CSV parsing choices. The writer stores the column types and nulls in a compressed Parquet file. Save this as archive.x and run arx run archive.x.

```
title: Archive five years of Beijing air-quality readings
```

import write_parquet from stdlib.parquet

import load_readings from readings


fn main() -> i32:
  readings: auto = load_readings()
  write_parquet(readings, "beijing-pm25.parquet", compression="zstd")
  print(readings.nrows())
  return 0

The output contains the same 43,824 rows and preserves all 2,067 missing PM2.5 measurements. A colleague can open it with PyArrow or another Parquet reader. For a larger archive, Arx also offers explicit batch readers for CSV and Parquet. Parquet guide

Time the whole command

Every command starts from the same downloaded CSV. Each parses it, selects the same five columns, and then does the task in the first column. Hyperfine measures the entire process, including startup, Python imports, and warm-cache CSV I/O. The download and compilation happen before timing.

Task from the CSV Arx 1.33.0 CPython 3.14.10 with PyArrow C++ at -O2
Load and count rows 15.1 ms 59.5 ms 19.2 ms
Load and summarize PM2.5 21.5 ms 81.0 ms 17.2 ms
Load and find five annual peaks 18.4 ms 77.7 ms 16.8 ms
Load and write Zstandard Parquet 19.7 ms 64.0 ms 18.0 ms

The timings are medians of 30 runs after five warmups on one Linux x86-64 host with an AMD EPYC 9V45. All three implementations use Arrow 26.0.1 and single-threaded CSV parsing. The outputs agreed, including the Parquet rows, column types, and nulls. The inventory is a baseline for a complete command. Each row reports the total elapsed time for its own command. Benchmark sources and reproduction commands

Where to take the dataset next

The same CSV is small enough to explore in JupyterLab with the ArxLang kernel or edit in VS Code with the early Arx extension. Vizx can draw a line chart of the five annual peaks, and ArxPM can manage the project when you start keeping the loader, analyses, and exports together. The source titles use Douki YAML docstrings. DoukiMD renders this post and the project’s API documentation. Jupyter kernel · VS Code · Vizx · ArxPM · Douki · DoukiMD

Arx is pre-production. This workflow uses an explicit schema for typed Series access and known calendar boundaries for the yearly analysis. Easier access to runtime schemas, more Arrow operations, and finer control over batch streams would make other analyses on the same data easier to express. The compiler roadmap also proposes a verified boundary between semantic analysis and code generation, giving future optimizations a clearer place to work. Language and data API milestones · Arrow integration plan · Compiler architecture plan

If you try the dataset, pull out a month or compare annual peaks with annual means. A small example on the issue tracker is welcome when you run into a rough edge. If you’d like to help sustain the compiler and its documentation, donate directly to ArxLang through Open Collective. Arx issue tracker

Search documentation

Type to search.