Skip to main content

SSB flextab

PyPI Status Python Version License

Documentation Tests Coverage Quality Gate Status

pre-commit Black Ruff Poetry

Features

Flextab is a Python package for making flexible tabulation. It is made with Claude AI, models Sonnet 4.5 and Sonnet 5.

Flextab is inspired by the Sas procedure proc tabulate which again was based on the tpl language

It makes flexible tables in two dimensions, rows an columns, based on Pandas dataframes.

Requirements

  • pandas
  • numpy
  • openpyxl when exporting tables to Excel

Installation

You can install SSB flextab via pip from PyPI:

pip install ssb-flextab

Usage

Import pandas and flextab.

import pandas as pd
from ssb_flextab import flextab

Demo dataframe.

df = pd.DataFrame({
    "sex":        ["1", "1", "2", "1", None, "2", "2", "1", "2", "2"],
    "age_group":  ["2", "1", "2", "3", "1", "2", "2", "2", "3", None],
    "region":     [None, "2", "1", "2", "2", "3", "3", "2", "2", "1"],
    "education":  ["3", "2", "3", "1", "3", "3", "3", "1", "3", "2"],
    "income":     [300, 100, 450, 200, 650, 750, None, 850, 400, 350],
    "tax":        [100, 10, 200, 90, 340, 370, 30, None, 150, 150],
    "weight":     [1.5, 3.2, 1.7, 2.2, 6.1, 4.2, 1.9, 4.8, None, 8.2],
})

Two dimensions with totals at the top/left.

flextab(
    data=df,
    groupby=["region", "sex"],
    table="""
    total region
    ,
    total sex
    """
)

Nested columns in the row and column dimensions with sub-totals.

flextab(
    data=df,
    groupby=["region", "sex", "age_group", "education"],
    table="""
    total region * (total age_group)
    ,
    total sex * (total education)
    """
)

Stacked columns in the row dimension and introduction of measure columns with different statsistics.

flextab(
    data=df,
    groupby=["region", "sex", "age_group"],
    measure="income",
    table="""
    total region age_group
    ,
    income * (count sum mean) * (total sex)
    """
)

Different percentages:

  • Percentage of grand total
  • Row percentages
  • Column percentages

The cells in the table are formatted with one decimal and decimal comma.

flextab(
    data=df,
    groupby=["region", "sex"],
    table="""
    total region
    ,
    (pctn rowpctn colpctn) *format=7,1 * (total sex)
    """
)

A comprehensive tutorial is found in the docs folder at the Statistics Norway github pages.

Contributing

Contributions are very welcome. To learn more, see the Contributor Guide.

License

Distributed under the terms of the MIT license, SSB flextab is free and open source software.

Issues

If you encounter any problems, please file an issue along with a detailed description.

Credits

This project was generated from Statistics Norway's SSB PyPI Template.

Metadata

Release files for ssb-flextab 0.9.4

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

Source distribution (sdist)

Source distribution for ssb-flextab 0.9.4
File Size Uploaded Provenance Actions
ssb_flextab-0.9.4.tar.gz 48.9 kB With provenance Details for ssb_flextab-0.9.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ssb-flextab 0.9.4
File Interpreter ABI Platform Actions
ssb_flextab-0.9.4-py3-none-any.whl Python 3 none any Details for ssb_flextab-0.9.4-py3-none-any.whl

Total release size: 98.1 kB

Release files / ssb_flextab-0.9.4.tar.gz

Download URL ssb_flextab-0.9.4.tar.gz
Size 48.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f490733e5af2edcc9e26e40095dc823c9c40a85f1573b0e8f8510331ae926b15
BLAKE2b-256 checksum
How to use checksums
450e61e7f4742456061d7db1d92902d4402066f4405f3e1b7e40feb56e6d01f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Release files / ssb_flextab-0.9.4-py3-none-any.whl

Download URL ssb_flextab-0.9.4-py3-none-any.whl
Size 49.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
324e2d82646b768625ce94d085d4dbd7b82cd2c964debd7ca470c41a5d99d30c
BLAKE2b-256 checksum
How to use checksums
4a1f3a095b147819e47517473cda88fb9025c4df0b2a40a5cf839ac834c078bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Security for ssb-flextab 0.9.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ssb_flextab-0.9.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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