Skip to main content
https://img.shields.io/pypi/v/clchoropleth.svg

clChoropleth

It creates a SVG Choropleth of a Chilean region.

Description

You need a Dictionary or a Pandas.Series with the values. The index or key can be the Comuna name and the value an int. The package uses “clcomuna” to get the comuna code, and it creates bins for the values. You can specify the comuna region, even if your data has comunas for the hole country.

Installation

pip3 install clchoropleth

Requirements

  • clcomuna

  • pandas

  • bf4 (BeautifulSoup)

  • Python3.3+

Usage:

>>> import clchoropleth

Example

import clchoropleth
arica = {'ARICA': 27, 'CAMARONES': 13, 'GENERAL LAGOS': 10, 'PUTRE': 8}
data = clchoropleth.prepare_data(arica)
clchoropleth.run(data, "arica.svg", "15")

This should save an SVG file similar to this:

arica.png

prepare_data

def prepare_data(data, t=70, noNone=False):

Prepares the dataset. If its a dictionary, it turns it into a pandas.Series object. It checks the comuna name and uses its code instead. You can specify the threshold for the clcomuna package. It aggregates by comuna code, so, for exmaple, if you have {'arica':10, 'Arica':11, 'ARICA':12} it will return 'arica':33 as a pd.Series. It can drops the ‘None’s that you will get for below the threshold. Returns a pd.Series

arica = {'ARICA': 27, 'CAMARONES': 13, 'GENERAL LAGOS': 10, 'PUTRE': 8, 'arica': 33}
clchoropleth.prepare_data(arica)
>>>
    15101    60
    15102    13
    15201     8
    15202    10
    dtype: int64

select_comunas_from_region

def select_comunas_from_region (data, region):

Given the dataset (after prepare_data), returns a subset with only the comunas from the given region. ‘region’ must be a string.

data = {'ARICA': 27, 'CAMARONES': 13, 'GENERAL LAGOS': 10, 'PUTRE': 8, 'arica': 33, 'iquique': 123, 'santiago': 999}
data_p = prepare_data(data)
data_p
>>>
    01101    123
    13101    999
    15101     60
    15102     13
    15201      8
    15202     10
    dtype: int64
select_comunas_from_region(data_p, "15")
>>>
    15101    60
    15102    13
    15201     8
    15202    10
    dtype: int64

discretize

def discretize(data, bins=5, quantile=False):

Changes the values of the data into a bin number. You can specify a number of bins to be used and if to use ‘quintile’ based cut or not.

arica
>>>
    15101    60
    15102    13
    15201     8
    15202    10
    dtype: int64
discretize(arica)
>>>
    15101    4
    15102    0
    15201    0
    15202    0
    dtype: category
    Categories (5, int64): [0 < 1 < 2 < 3 < 4]
discretize(arica, 4, True)
>>>
    15101    3
    15102    2
    15201    0
    15202    1
    dtype: category
    Categories (4, int64): [0 < 1 < 2 < 3]

make_map

def make_map(data, filename, region, colors='orange'):

It creates the choropleth map and saves it to filename destination.

Args:

data: The pd.Series with the data. The index needs to be the code and the value the bin number.

filename: The filename of the map we are going to save.

region: we need to specify the region again, as a string (“09”), to open the original svg file and modify it.

colors: it can be a string, if is one of the 5 pre-set color lists: orange, blue, green, red, pruple. Or it can be a list of strings, with each string being a color. For example:[‘#ffffcc’,’#c2e699’,’#78c679’,’#31a354’,’#006837’] It needs to have the same length as the number of bins. For more colors: http://colorbrewer2.org/

Returns:

It saves the map. No return valule.

run

def run(data, filename, region, colors='orange', bins=5, quantile=False):

Is a wrapper function that runs all the other functions of the module, except for ‘preapare_data’. Doesn’t return anything.

Metadata

Release files for clchoropleth 1.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 clchoropleth 1.2
File Size Uploaded Provenance Actions
clchoropleth-1.2.tar.gz 1.2 MB Without provenance Details for clchoropleth-1.2.tar.gz

Release files / clchoropleth-1.2.tar.gz

Download URL clchoropleth-1.2.tar.gz
Size 1.2 MB
Tags Source
SHA-256 checksum
How to use checksums
871a9bb4599b360f6973408b61d8388d83b7cfec4fd93a4bee4ad98833b6e633
BLAKE2b-256 checksum
How to use checksums
d650785be4c3ee816543c8ba1b8ddb9e385ee030a6c2cc1657089b2658b9a439
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for clchoropleth 1.2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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