{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Columns\n", "\n", "[[Polars Documentation](https://docs.pola.rs/api/python/stable/reference/expressions/columns.html)]\n", "\n", "`pl.col(\"A\")` or `pl.col.A` starts an expression by selecting a column named \"A\".\n", "While the Polars Library allows for multiple columns to be selected simultaneously\n", "(via `pl.col(\"*\")`, `pl.col(\"A\", \"B\")`, `pl.col(pl.String)`, `pl.exclude`, and so on),\n", "the OpenDP Library currently only supports selection of one column at a time.\n", "The column name may be changed via `.alias`." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import polars as pl\n", "import opendp.prelude as dp\n", "\n", "dp.enable_features(\"contrib\")\n", "\n", "work_hours_cols = [\"HWUSUAL\", \"HWACTUAL\"]\n", "\n", "# not recommended, OpenDP will reject this joint expression over multiple columns\n", "single_expr = pl.col(work_hours_cols).cast(int).dp.sum((0, 60))\n", "\n", "# build individual expressions for each query\n", "split_exprs = [pl.col(c).cast(int).dp.sum((0, 60)) for c in work_hours_cols]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Demonstration of use:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
column | aggregate | distribution | scale |
---|---|---|---|
str | str | str | f64 |
"HWUSUAL" | "Sum" | "Integer Laplace" | 4320.0 |
"HWACTUAL" | "Sum" | "Integer Laplace" | 4320.0 |