Skip to main content

polars_ipums

A package to work with IPUMS microata in Python. Used in-house at Opportunity Insights.

Example

# convert IPUMS microdata export to a hive-partioned Parquet dataset

import polars as pl
from polars_ipums import create_parquet_dataset

input_path = "~/Downloads/ipums_export"
output_path = "~/Desktop/parquet_ipums"

labels = {
    # use the default IPUMS labels for the sex column
    "sex": {},
    # use custom labels for the race/hispanic origin column
    "rachsing": {
        "White": "White",
        "Black/African American": "Black",
        "American Indian/Alaska Native": "AIAN",
        "Asian/Pacific Islander": "Asian",
        "Hispanic/Latino": "Hispanic",
    },
}

# give a few columns more human-readable names
renames = {
    "rachsing": "race",
    "countyfip": "county",
    "ftotinc": "family_income",
    "hhincome": "household_income",
}

# custom education column!
educd = pl.col("educd")
my_education = (
    pl.when(educd.le(61))
    .then(0)
    .when(educd.is_between(62, 64))
    .then(1)
    .when(educd.is_between(65, 100))
    .then(2)
    .when(educd.is_between(101, 116))
    .then(3)
    .alias("my_education")
)

create_parquet_dataset(
    input_path,
    output_path,
    labels=labels,
    partition_by=["year"],
    renames=renames,
    additional_columns=[my_education],
    override_output=True,
    verbose=True,
)

# load a few rows back into memory
ipums_microdata = (
    pl.scan_parquet(output_path / "**/*.parquet", hive_partitioning=True)
    .head()
    .collect()
)

Metadata

Release files for polars_ipums 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for polars_ipums 0.0.1
File Size Uploaded
polars_ipums-0.0.1.tar.gz 5.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for polars_ipums 0.0.1
File Interpreter ABI Platform
polars_ipums-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 12.3 kB

Release files / polars_ipums-0.0.1.tar.gz

Download URL polars_ipums-0.0.1.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
023364e25929a440fa88eb91855000b44bf5ae9e8a80c893c94f6dd3a0e892d2
BLAKE2b-256 checksum
How to use checksums
0dfbcff977372cc836f69cb20de96a0e2cf5a6e46a05ce7da3e96900bdc01704
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.23

Release files / polars_ipums-0.0.1-py3-none-any.whl

Download URL polars_ipums-0.0.1-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
78c3dd52d36bfa91be37771fb29103133e2a386a52d31e397ce1eecfa8a0c838
BLAKE2b-256 checksum
How to use checksums
42f7da44da173749206e205e19fb1bb01717f5ad67afca8e1ca76aa09a220ab7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.23

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page