The Nanuq Book
Nanuq brings Polars DataFrames to Nim. This book takes public Polars tutorials and examples and ports them to Nanuq, one chapter at a time.
Every chapter runs. Each example comes in two tabs: Nim, computed by Nanuq, and Python, the original code run with Python Polars when the book is built. Pick a tab once and every example follows. Nanuq wraps the same Polars code as Python Polars 2.1, the version the Python side runs, so the two tabs show the same results.
Hello, world
A DataFrame of greetings, and a query that keeps the languages with more than 100 million speakers (rough figures):
import nanuq
let greetings = newDataFrame:
language: ["English", "Italian", "French"]
hello: ["Hello, world!", "Ciao, mondo!", "Bonjour, le monde !"]
speakers_millions: [1500, 68, 310]
nbShow greetings.filter(col.speakers_millions > 100)
| language | hello | speakers_millions |
|---|---|---|
| str | str | i64 |
| "English" | "Hello, world!" | 1500 |
| "French" | "Bonjour, le monde !" | 310 |
import polars as pl
greetings = pl.DataFrame({
"language": ["English", "Italian", "French"],
"hello": ["Hello, world!", "Ciao, mondo!", "Bonjour, le monde !"],
"speakers_millions": [1500, 68, 310],
})
greetings.filter(pl.col("speakers_millions") > 100)| language | hello | speakers_millions |
|---|---|---|
| str | str | i64 |
| "English" | "Hello, world!" | 1500 |
| "French" | "Bonjour, le monde !" | 310 |
Sources and licences
Each ported chapter starts with a box that names its source, its authors and its licence, and says what the port changed. The sources and their licences are listed in Sources and licences. The book's own text and code are MIT licensed.
Which version of Nanuq
Nanuq is young and its API still changes. The book is built against a pinned release of Nanuq, and is checked every week against Nanuq's main branch, so that changes that break a chapter show up early.
import nanuqbook
bookInit()
nbText: """
# The Nanuq Book
[Nanuq](https://github.com/pietroppeter/nanuq) brings [Polars](https://pola.rs) DataFrames
to Nim. This book takes public Polars tutorials and examples and ports them to Nanuq, one
chapter at a time.
Every chapter runs. Each example comes in two tabs: **Nim**, computed by Nanuq, and
**Python**, the original code run with Python Polars when the book is built. Pick a tab
once and every example follows. Nanuq wraps the same Polars code as Python Polars 2.1, the
version the Python side runs, so the two tabs show the same results.
## Hello, world
A DataFrame of greetings, and a query that keeps the languages with more than 100 million
speakers (rough figures):
"""
tabs """
import polars as pl
greetings = pl.DataFrame({
"language": ["English", "Italian", "French"],
"hello": ["Hello, world!", "Ciao, mondo!", "Bonjour, le monde !"],
"speakers_millions": [1500, 68, 310],
})
greetings.filter(pl.col("speakers_millions") > 100)
""":
nbCode:
import nanuq
let greetings = newDataFrame:
language: ["English", "Italian", "French"]
hello: ["Hello, world!", "Ciao, mondo!", "Bonjour, le monde !"]
speakers_millions: [1500, 68, 310]
nbShow greetings.filter(col.speakers_millions > 100)
nbText: """
## Sources and licences
Each ported chapter starts with a box that names its source, its authors and its licence,
and says what the port changed. The sources and their licences are listed in
[Sources and licences](licences.html). The book's own text and code are MIT licensed.
## Which version of Nanuq
Nanuq is young and its API still changes. The book is built against a pinned release of
Nanuq, and is checked every week against Nanuq's main branch, so that changes that break a
chapter show up early.
"""
bookSave()
On GitHub: book/index.nim