Skip to main content

Simple categorisation

Define categories and sub-categories with predicates, and categorise lists of items based on these categories:

cat = Categoriser()
# The category of items that are < 0.5
cat.add("x < 0.5", lambda x: x < 0.5)
# Items over 1
over_1 = cat.add("x >= 1", lambda x: x >= 1)
# Items between 1.1 and 1.2, as a subcategory of items over 1
over_1.add("1.2 > x >= 1.1", lambda x: 1.2 > x >= 1.1)
over_1.add("x > 1.2", lambda x: x >= 1.2)

result = cat.categorise_list([0.01, 0.6, 1.001, 1.05, 1.1, 1.2, 3])
summarised = result.summarise()
print(summarised)

This should show something along the lines of:

{
    "categories": [
        {"category_name": "x < 0.5", "matches": 1},
        {
            "category_name": "x >= 1", "matches": 5,
            "categories": [
                {"category_name": "1.2 > x >= 1.1", "matches": 1},
                {"category_name": "x > 1.2", "matches": 2},
                {"unmatched_items": 2}
            ]
        },
        {"unmatched_items": 1}
    ]
}

It is possible to obtain a Sankey diagram with plotly for the same example.

First, install plotly

pip install plotly

Then:

parameters = result.plotly_sankey(top_label="Top")

import plotly.graph_objects as go
fig = go.Figure(data=[go.Sankey(parameters)])
fig.update_layout(title_text="Example Sankey Diagram", font_size=20)
fig.show()

Release files for simple-categorisation 0.2

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

Source distribution (sdist)

Source distribution for simple-categorisation 0.2
File Size Uploaded
simple-categorisation-0.2.tar.gz 4.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for simple-categorisation 0.2
File Interpreter ABI Platform
simple_categorisation-0.2-py3-none-any.whl Python 3 none any Details

Total release size: 9.1 kB

Release files / simple-categorisation-0.2.tar.gz

Download URL simple-categorisation-0.2.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ada655087a0902c33bb142764fd3c447ab50be7a92130f8a39ad47ec7659cb50
BLAKE2b-256 checksum
How to use checksums
3b805058273f874e83c2c7b2cf6d74a84724c4703da47a29d6611966a7578e82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.2

Release files / simple_categorisation-0.2-py3-none-any.whl

Download URL simple_categorisation-0.2-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4974aad28bf8d927a6406e2dd16168d773362f4721988b37523c7d8247021d97
BLAKE2b-256 checksum
How to use checksums
c508882dddfb01e7f17102c2efc8868644a15fe8234da27a002d4f052d6df1da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.2

Release history Release notifications | RSS feed

This release

0.2 This release

2 release files

0.1

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