Skip to main content

Create simple, tastefully-formatted strings that resemble tables

Project description

Table Maker

Description

Make simple tables from rows and columns, with values separated into cells and the contents left-justified.

Initially designed for creating map marginalia in QGIS and ArcMap, as well as a susbtitute for the often over-engineered and clunky table wizards that are featured in word processors.

Installation

At some point: pip install table_maker

Usage

Most basic use is to create a simple, cleanly-formatted table:

  >>> from table_maker import make_table
  >>> cols = ('athlete', 'time')
  >>> rows = (('Clint', '16:04'), ('Mitch', '12:12'),('Tommy', '22:57'), ('Zach', '27:56'))
  >>> print(make_table(cols, rows, sort_col=1))
  +--------+--------+
  | athlete| time   |
  +========+========+
  | Mitch  | 12:12  |
  +--------+--------+
  | Clint  | 16:04  |
  +--------+--------+
  | Tommy  | 22:57  |
  +--------+--------+
  | Zach   | 27:56  |
  +--------+--------+

That's mostly it, but it does have a few simple utilities, for example, you can add some row numbers if you like:

  >>> import table_maker as tm
  >>> cols = ('u-boat', 'commissioned', 'sunk')
  >>> rows = (
  ...  ('u-64', '16 Dec 39', '13 Apr 40'), 
  ...  ('u-104', '19 Aug 40', '28 Nov 40'),  
  ...  ('u-107', '08 Oct 40', '08 Aug 44'))
  >>> uboats = tm.insert_row_numbers(tm.make_table(cols, rows))
  >>> print(uboats)
      +--------------+--------------+--------------+
      | u-boat       | commissioned | sunk         |
      +==============+==============+==============+
   1  | u-64         | 16 Dec 39    | 13 Apr 40    |
      +--------------+--------------+--------------+
   2  | u-104        | 19 Aug 40    | 28 Nov 40    |
      +--------------+--------------+--------------+
   3  | u-107        | 08 Oct 40    | 08 Aug 44    |
      +--------------+--------------+--------------+

Or you can remove separators from the rows if you want a more compact table, and convert items to title case if you like:

>>> import table_maker as tm
>>> cols = ('album', 'year')
>>> rows = (('fandango!', '1975'), ('tres hombres', '1973'),('eliminator', '1983'))
>>> x, y = tm.capitalize_inputs(cols, rows)
>>> print(tm.remove_seps(tm.make_table(cols=x, rows=y, scaling=1.1, sort_col=1)))
+--------------+--------------+
| Album        | Year         |
+==============+==============+
| Tres Hombres | 1973         |
| Fandango!    | 1975         |
| Eliminator   | 1983         |
+--------------+--------------+

There are no utilities for selecting rows, you are better off doing that ahead of time. For example let's say you want to make a table like from this string:

>>> csv = '''first,last,GOATscore,rank
Kareem,Abdul-Jabbar,5.600
LeBron,James,5.511
Michael,Jordan,5.219
Tim,Duncan,4.273
Bill,Russell,4.066
Kobe,Bryant,4.021
Wilt,Chamberlain,3.885
Karl,Malone,3.823
Shaquille,O'Neal,3.820
Julius,Erving,3.502
...
'''

Then you only want players whose score is above 4, it's easiet to get that before creating the table:

>>> import table_maker as tm
>>> cols = csv.split()[0].split(',')
>>> rows = [item.split(',') for item in csv.split('\n')[1:] if item]
>>> above_4 = [row for row in rows if float(row[2]) > 4] 
>>> table = tm.make_table(cols, above_4, sort_col=-1, reverse=True, scaling=1.25)
>>> print(tm.insert_title("   the greatest of all time", tm.insert_row_numbers(table)))
   THE GREATEST OF ALL TIME
   +---------------+---------------+---------------+
   | first         | last          | GOATscore     |
   +===============+===============+===============+
1  | Kareem        | Abdul-Jabbar  | 5.600         |
   +---------------+---------------+---------------+
2  | LeBron        | James         | 5.511         |
   +---------------+---------------+---------------+
3  | Michael       | Jordan        | 5.219         |
   +---------------+---------------+---------------+
4  | Tim           | Duncan        | 4.273         |
   +---------------+---------------+---------------+
5  | Bill          | Russell       | 4.066         |
   +---------------+---------------+---------------+
6  | Kobe          | Bryant        | 4.021         |
   +---------------+---------------+---------------+

Alternatively, you could use the transform function to convert the table into a dictionary, which is conveniently designed to be compatible with the pandas.DataFrame.from_dict() method, turn it into a dataframe and process it that way.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

table_maker-0.1.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

table_maker-0.1.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file table_maker-0.1.0.tar.gz.

File metadata

  • Download URL: table_maker-0.1.0.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for table_maker-0.1.0.tar.gz
Algorithm Hash digest
SHA256 537b2e7ec344e5b6899f9d501d0b7cb48f54dcbd46978dcf016733a11a0d185c
MD5 f76e83c8b0d9d348c87418d8ef1ecf1b
BLAKE2b-256 86188d9a1edf66b33a2db1d4c8d739df9c2a6fb015069233ab47578cf4c66f61

See more details on using hashes here.

File details

Details for the file table_maker-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: table_maker-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for table_maker-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fe010425b62e621485274331805ad2717dea0f7d6f8156bafbef04bf7f1958f1
MD5 958df6fbedb357a8ed7f2e069479d8e9
BLAKE2b-256 fa7ac6557f65e3f5b06ac636986327c036b08c538b36a8d32b333500f4773831

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page