{ "info": { "author": "Peter Zagubisalo", "author_email": "peter.zagubisalo@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Topic :: Software Development :: Build Tools" ], "description": "# Tabulate Helper\n\nConverts tabular data like Pandas dataframe to GitHub Flavored Markdown pipe table (wrapper around [tabulate](https://pypi.org/project/tabulate/) module). I use it with [Pandoctools/Knitty](https://github.com/kiwi0fruit/pandoctools).\n\n\n# Contents\n\n* [Tabulate Helper](#tabulate-helper)\n* [Contents](#contents)\n* [Install](#install)\n* [Differences from tabulate module](#differences-from-tabulate-module)\n* [Usage example](#usage-example)\n* [Converting to other formats](#converting-to-other-formats)\n* [API](#api)\n\n\n# Install\n\nVia conda:\n\n```\nconda install -c defaults -c conda-forge tabulatehelper\n```\n\nVia pip:\n\n```\npip install tabulatehelper\n```\n\n\n# Differences from tabulate module\n\n* With defaults: auto-headers for Pandas data frames,\n* With defaults: auto-empty headers for GitHub compatibility,\n* Special function that prints header only (useful at the end of long tables),\n* Doesn't show index by default,\n* `formats` argument can be set that selectively overrides automatic align format.\n\nExample:\n```py\nimport numpy as np\nimport pandas as pd\nfrom tabulate import tabulate\nimport tabulatehelper as th\n\ndf = pd.DataFrame(np.random.random(16).reshape(4, 4), columns=('a', 'b', 'c', 'd'))\n\n# tabulate wtithout wrapper:\ntbl = tabulate(df, df.columns, tablefmt='pipe', showindex=False)\n\n# tabulate helper with overriding align format:\ntbl = th.md_table(df, formats={-1: 'c'})\n\nprint(tbl)\n```\n\nOutput:\n```\n| a | b | c | d |\n|---------:|---------:|---------:|:--------:|\n| 0.413284 | 0.932373 | 0.277797 | 0.646333 |\n| 0.552731 | 0.381826 | 0.141727 | 0.2483 |\n| 0.779889 | 0.012458 | 0.308352 | 0.650859 |\n| 0.301109 | 0.982111 | 0.994024 | 0.43551 |\n```\n\n\n## Usage example\n\nMain functions are `tabulatehelper.md_table(...)` and `tabulatehelper.md_header(...)`. Usage example that works both in Atom+Hydrogen and in Pandoctools+Knitty:\n\n```py\nfrom IPython.display import Markdown\nimport pandas as pd\nimport numpy as np\nimport tabulatehelper as th\n\ndf = pd.DataFrame(np.random.random(16).reshape(4, 4))\n\n# appended header is useful when very long table\n# (can display `df.iloc[[0]]` in hydrogen)\nMarkdown(f\"\"\"\n\n{th.md_table(df)}\n\n: Table {{#tbl:table1}}\n\n{th.md_header(df)}\n\n\"\"\")\n```\n\n\n# Converting to other formats\n\nTabulate can convert to other formats but I prefer using [pypandoc](https://pypi.org/project/pypandoc/) on `th.md_table` output as it can convert to any Pandoc supported [output format](https://pandoc.org/MANUAL.html#general-options).\n\n\n# API\n\nFrom [tabulate_helper.py](https://github.com/kiwi0fruit/tabulatehelper/tree/master/tabulatehelper/tabulate_helper.py):\n\n```py\ndef md_table(tabular_data: Union[pd.DataFrame, object],\n headers: tuple = None,\n showindex: Union[bool, None] = False,\n formats: Union[dict, str, Iterable[str]] = None,\n return_headers_only: bool = False,\n **kwargs) -> str:\n \"\"\"\n Converts tabular data like Pandas dataframe to\n GitHub Flavored Markdown pipe table.\n\n Markdown table ``formats`` examples:\n\n * ``dict(foo='-:', bar=':-:', **{-1: 'c'})``,\n * ``'--|-:|:-:'`` or ``'|--|-:|:-:|'`` or ``-rc``,\n * ``['--', '-:', 'C']``\n\n Parameters\n ----------\n tabular_data :\n tabulate.tabulate(tabular_data[,...]) argument\n headers :\n tabulate.tabulate(..., headers[,...]) optional argument.\n If None and tabular_data is pd.DataFrame then default is\n tabular_data.columns converted to Tuple[str, ...].\n If None then use tabulate.tabulate(...) default\n (but in this particular case if it's absent in the output\n then add blank header).\n showindex :\n tabulate.tabulate(..., showindex[,...]) optional argument.\n formats :\n GitHub Flavored Markdown table align formats: dict, str or list / iterable.\n '-' mean lack of align format, 'l'/'L'/':-' mean left align,\n 'r'/'R'/'-:' mean right align, 'c'/'C'/':-:' mean center align.\n dict keys are for tabulate output headers so they should be str.\n int keys mean column number.\n return_headers_only :\n returns only table header + empty row.\n If header is absent then returns empty string.\n kwargs :\n Other tabulate.tabulate(...) optional keyword arguments\n\n Returns\n -------\n md :\n Markdown table\n \"\"\"\n ...\n```", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/kiwi0fruit/tabulatehelper", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "tabulatehelper", "package_url": "https://pypi.org/project/tabulatehelper/", "platform": "", "project_url": "https://pypi.org/project/tabulatehelper/", "project_urls": { "Homepage": "https://github.com/kiwi0fruit/tabulatehelper" }, "release_url": "https://pypi.org/project/tabulatehelper/0.0.7/", "requires_dist": null, "requires_python": ">=3.6", "summary": "Converts tabular data like Pandas dataframe to GitHub Flavored Markdown table (wrapper around tabulate module).", "version": "0.0.7" }, "last_serial": 4725142, "releases": { "0.0.6": [ { "comment_text": "", "digests": { "md5": "dbaf7650f5b954091dcd30c73c0cafc4", "sha256": "5d75662daca8043d7ce32fa552e0792c5794f4c2405b726ced0d1ac0ac5e593d" }, "downloads": -1, "filename": "tabulatehelper-0.0.6.tar.gz", "has_sig": false, "md5_digest": "dbaf7650f5b954091dcd30c73c0cafc4", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 21774, "upload_time": "2019-01-22T09:28:22", "url": "https://files.pythonhosted.org/packages/20/22/bff476f359fef57112eff85ec0eb6f82d2151d003b9f2d78beb55afbbcf7/tabulatehelper-0.0.6.tar.gz" } ], "0.0.7": [ { "comment_text": "", "digests": { "md5": "eefc5753842ce355a0cde20fbbca1a6c", "sha256": "2c9add9b3349dbad2dc875797713d901a22151f67a66d7157d282267ad3199d7" }, "downloads": -1, "filename": "tabulatehelper-0.0.7.tar.gz", "has_sig": false, "md5_digest": "eefc5753842ce355a0cde20fbbca1a6c", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 21780, "upload_time": "2019-01-22T09:35:46", "url": "https://files.pythonhosted.org/packages/f0/63/3c3ea3a28821bdc620b205cbc66c57437ed894bbd9a77970973ad7cd81bd/tabulatehelper-0.0.7.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "eefc5753842ce355a0cde20fbbca1a6c", "sha256": "2c9add9b3349dbad2dc875797713d901a22151f67a66d7157d282267ad3199d7" }, "downloads": -1, "filename": "tabulatehelper-0.0.7.tar.gz", "has_sig": false, "md5_digest": "eefc5753842ce355a0cde20fbbca1a6c", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 21780, "upload_time": "2019-01-22T09:35:46", "url": "https://files.pythonhosted.org/packages/f0/63/3c3ea3a28821bdc620b205cbc66c57437ed894bbd9a77970973ad7cd81bd/tabulatehelper-0.0.7.tar.gz" } ] }