Skip to content

Instantly share code, notes, and snippets.

@Shoeboxam
Created June 24, 2024 22:33
Show Gist options
  • Save Shoeboxam/ef0eb5e2d2f75421cf2c3879cd3f9b26 to your computer and use it in GitHub Desktop.
Save Shoeboxam/ef0eb5e2d2f75421cf2c3879cd3f9b26 to your computer and use it in GitHub Desktop.
import polars as pl
import opendp.prelude as dp
dp.enable_features("contrib")
# set up your analysis
context = dp.Context.compositor(
data=pl.scan_csv("grade_pets.csv"),
privacy_unit=dp.unit_of(contributions=1),
privacy_loss=dp.loss_of(epsilon=1.),
split_evenly_over=3,
margins={("grade",): dp.Margin(
public_info="keys",
max_partition_length=100)
})
# define a query to count the number of pets per grade
query = context.query() \
.group_by("grade") \
.agg(pl.col("pets").fill_null(0).dp.sum(bounds=(0, 10)))
release = query.release().collect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment