Giter Club home page Giter Club logo

clcomuna's Introduction

https://travis-ci.org/slarrain/clcomuna.svg?branch=master

clcomuna

Very simple package that, given the name of a comuna from Chile, returns its code

Description

Each comuna in Chile has a unique code that makes easier to map them to different attributes (e.g. choropleth). Since I was going through the hassle of doing it each time I had a new project, I decided to build a very simple tool that could automate the task. I hope this can be of use to other developers / civic-hackers.

I added a fuzzy version for cases where there was no exact match.

Features

  • Given a comuna name, it returns its code, taking care of special characters, uppercases and lowercases.
  • If it doesn't find an exact match, it prints that and returns None
  • A fuzzy function returns the best match (uses fuzzywuzzy)
  • You can specify to print the score of the fuzzy match
  • You can specify a threshold above which it should return a match and below which it shouldn't.
  • There is a function that tries the exact match and if it doesn't find it, it goes to the fuzzy version.
  • The list of comunas-code is a simple CSV file for easier edition.
  • If you want some comuna name version added to the csv file, just contact me and I'll add them right away.

Installation

pip3 install clcomuna

Requirements

  • fuzzywuzzy
  • Python3.3+

Usage:

>>> import clcomuna

(If there is a warning, ignore it. It comes with the dependency)

get_code

>>> clcomuna.get_code("peumo")
'06112'

get_fuzzy: returns name, not code

>>> clcomuna.get_fuzzy("alragobo")
'ALGARROBO'
>>> clcomuna.get_fuzzy("alragobo", True)
('ALGARROBO', 71)
'ALGARROBO'
>>> clcomuna.get_fuzzy("alragobo", True, 72)
('ALGARROBO', 71)
Score lower than minimum threshold for comuna: ALRAGOBO - ALGARROBO

The optional second parameter True prints the found comuna and the score. The optional third parameter int stablishes a threshold for the function to return the best name match

get_steps

>>> clcomuna.get_steps("alragobo")
Could not find code for:  ALRAGOBO
'ALGARROBO'
>>> clcomuna.get_steps("alragobo", False, 74)
Score lower than minimum threshold for comuna: ALRAGOBO - ALGARROBO

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.