{"id":17321971,"url":"https://github.com/petercorke/ansitable","last_synced_at":"2025-05-07T04:09:43.230Z","repository":{"id":38449977,"uuid":"298911001","full_name":"petercorke/ansitable","owner":"petercorke","description":"Quick, easy and pretty display of tabular data or matrices, with optional ANSI color and borders","archived":false,"fork":false,"pushed_at":"2024-12-10T22:44:18.000Z","size":7682,"stargazers_count":18,"open_issues_count":3,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-07T04:09:08.895Z","etag":null,"topics":["ansi-art","ansi-colors","array","borders","columnar","csv","formatting","html","latex","markdown","matrix","pandas","restructured-text","table","tabular-data","tabular-data-formatter"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/petercorke.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-26T22:37:14.000Z","updated_at":"2025-02-01T18:57:23.000Z","dependencies_parsed_at":"2024-06-12T15:39:40.358Z","dependency_job_id":"d0c069ff-8cbf-4316-8a58-70013d95cd04","html_url":"https://github.com/petercorke/ansitable","commit_stats":{"total_commits":116,"total_committers":3,"mean_commits":"38.666666666666664","dds":"0.025862068965517238","last_synced_commit":"1fd2e999c4a6b6941be97ee53956b0d0839ad0fc"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petercorke%2Fansitable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petercorke%2Fansitable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petercorke%2Fansitable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petercorke%2Fansitable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/petercorke","download_url":"https://codeload.github.com/petercorke/ansitable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252810273,"owners_count":21807759,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansi-art","ansi-colors","array","borders","columnar","csv","formatting","html","latex","markdown","matrix","pandas","restructured-text","table","tabular-data","tabular-data-formatter"],"created_at":"2024-10-15T13:40:30.437Z","updated_at":"2025-05-07T04:09:43.208Z","avatar_url":"https://github.com/petercorke.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![PyPI version fury.io](https://badge.fury.io/py/ansitable.svg)](https://pypi.python.org/pypi/ansitable/)\n[![Anaconda version](https://anaconda.org/conda-forge/ansitable/badges/version.svg)](https://anaconda.org/conda-forge/ansitable)\n[![pyversions](https://img.shields.io/pypi/pyversions/ansitable)](https://pypi.python.org/pypi/ansitable/)\n[![Build Status](https://github.com/petercorke/ansitable/actions/workflows/master.yml/badge.svg)](https://github.com/petercorke/ansitable/actions?query=workflow%3Abuild)\n[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/petercorke/ansitable/graphs/commit-activity)\n[![GitHub license](https://img.shields.io/github/license/Naereen/StrapDown.js.svg)](https://github.com/petercorke/ansitable/blob/master/LICENSE)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/ansitable)](https://pypistats.org/packages/ansitable)\n\n\n\u003ctable style=\"border:0px\"\u003e\n\u003ctr style=\"border:0px\"\u003e\n\u003ctd style=\"border:0px\"\u003e\n\u003cimg src=\"https://github.com/petercorke/ansitable/raw/master/figs/ansi_logo.png\" width=\"300\"\u003e\u003c/td\u003e\n\u003ctd style=\"border:0px\"\u003e\nPretty tables and matrices for Python\u003c/a\u003e\n\u003cul\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/petercorke/ansitable\"\u003eGitHub repository \u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://petercorke.github.io/ansitable\"\u003eDocumentation\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003eDependencies: \u003ca href=\"https://dslackw.gitlab.io/colored\"\u003ecolored\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n# Synopsis\n\n\nCreate a table programatically from Python, or import a table from a Pandas dataframe which is also an easy way to read an Excel or CSV file. Display your table on the console or render it to a popular markup language such as HTML, Markdown, reStructured text, LaTeX or wikitable.\n\n* [Tables of data](#tables)\n* [Matrices](#matrices)\n\n\n### What's new\n\n0.11.2:\n\n- export a table in HTML format\n- export a table in ReST format\n- export a table in wikitable format\n- improved format override for a single cell, using `Cell`\n\n0.11.0:\n\n- [Pandas integration](https://pandas.pydata.org). Convert a Pandas DataFrame to a table, or vice versa\n- export a table in CSV format\n- added unit tests for the various conversion methods\n\n0.10.0:\n\n- `colsep` is now the number of padding spaces on each side of the cell data.  `colsep=1` means one space on the left and one on the right, previously this was achieved by `colsep=2`.\n- the padding now has `bgcolor`\n- the method `rule()` adds a horizontal dividing line across the table (actually this is from a few releases ago)\n- `row()` has arguments to override the fgcolor, bgcolor and style of all columns in the row, useful for highlighting a row.\n\n0.9.10:\n\n- fix problems due to changes with [`colored`](https://pypi.org/project/colored) 2.x\n  \n0.9.5:\n\n- methods to format table as MarkDown or LaTeX\n- work with Python 3.4\n\n0.9.3:\n\n- create matrices as well as tables\n- option to suppress color output\n\n# Tables\n\nPainless creation of nice-looking tables of data for Python.\n\n![colored table](https://github.com/petercorke/ansitable/raw/master/figs/colortable.png) \n\n## Starting simple\n\n```python\n 1 | from ansitable import ANSITable, Column\n 2 |\n 3 | table = ANSITable(\"col1\", \"column 2 has a big header\", \"column 3\")\n 4 | table.row(\"aaaaaaaaa\", 2.2, 3)\n 5 | table.row(\"bbbbbbbbbbbbb\", 5.5, 6)\n 6 | table.row(\"ccccccc\", 8.8, 9)\n 7 | table.print()\n\n```\nLine 3 constructs an `ANSITable` object and the arguments are a sequence of \ncolumn names followed by `ANSITable` keyword arguments - there are none in this first example.  Since there are three column names this this will be \na 3-column table.\nLines 4-6 add rows, 3 data values for each row.\n\nLine 7 prints the table and yields a tabular display\nwith column widths automatically chosen, and headings and column \ndata all right-justified (default)\n\n```\n         col1  column 2 has a big header  column 3  \n    aaaaaaaaa                        2.2         3  \nbbbbbbbbbbbbb                        5.5         6  \n      ccccccc                        8.8         9  \n```\n\nBy default output is printed to the console (`stdout`) but we can also:\n\n- provide a `file` option to `.print()` to allow writing to a specified output stream, the\ndefault is `stdout`.\n- obtain a multi-line string version of the entire table as `str(table)`.\n\nThe more general solution is to provide a sequence of `Column` objects which \nallows many column specific options to be given, as we shall see later. \nFor now though, we could rewrite the example above as:\n\n```python\ntable = ANSITable(\n        Column(\"col1\"),\n        Column(\"column 2 has a big header\"),\n        Column(\"column 3\")\n    )\n```\n\nor as\n\n```python\ntable = ANSITable()\ntable.addcolumn(\"col1\")\ntable.addcolumn(\"column 2 has a big header\")\ntable.addcolumn(\"column 3\")\n```\nwhere the keyword arguments to `.addcolumn()` are the same as those for\n`Column` and are given below.\n\n***\nWe can specify a [Python `format()` style format string](https://docs.python.org/3/library/string.html#formatspec) for any column - by default it\nis the general formatting option `\"{}\"`.\nYou may choose to left or right justify values via the format string, `ansitable` provides control over how those resulting strings are justified within the column.\n\n```python\ntable = ANSITable(\n        Column(\"col1\"),\n        Column(\"column 2 has a big header\", \"{:.3g}\"),  # CHANGE\n        Column(\"column 3\", \"{:-10.4f}\")\n    )\ntable.row(\"aaaaaaaaa\", 2.2, 3)\ntable.row(\"bbbbbbbbbbbbb\", 5.5, 6)\ntable.row(\"ccccccc\", 8.8, 9)\ntable.print()\n```\nwhich yields\n\n```\n         col1  column 2 has a big header    column 3  \n    aaaaaaaaa                        2.2      3.0000  \nbbbbbbbbbbbbb                        5.5      6.0000  \n      ccccccc                        8.8      9.0000  \n      \n```\nAlternatively we can specify the format argument as a function that converts\nthe value to a string.\n\n\n***\nThe data in column 1 is quite long, we might wish to set a maximum column width which\nwe can do using the `width` argument\n\n```python\ntable = ANSITable(\n        Column(\"col1\", width=10),                      # CHANGE\n        Column(\"column 2 has a big header\", \"{:.3g}\"),\n        Column(\"column 3\", \"{:-10.4f}\")\n    )\ntable.row(\"aaaaaaaaa\", 2.2, 3)\ntable.row(\"bbbbbbbbbbbbb\", 5.5, 6)\ntable.row(\"ccccccc\", 8.8, 9)\ntable.print()\n```\nwhich yields\n\n\n```\n      col1  column 2 has a big header    column 3  \n aaaaaaaaa                        2.2      3.0000  \nbbbbbbbbb…                        5.5      6.0000  \n   ccccccc                        8.8      9.0000  \n\n```\nwhere we see that the data in column 1 has been truncated.\n\nIf you don't like the ellipsis you can turn it off, and get to see one more\ncharacter, with the `ANSITable` option `ellipsis=False`.  The Unicode ellipsis\ncharacter u+2026 is used.\n\n## Borders\nWe can add a table border made up of regular ASCII characters\n\n```python\ntable = ANSITable(\n        Column(\"col1\"),\n        Column(\"column 2 has a big header\"),\n        Column(\"column 3\"),\n        border=\"ascii\"                          # CHANGE\n    )\ntable.row(\"aaaaaaaaa\", 2.2, 3)\ntable.row(\"bbbbbbbbbbbbb\", 5.5, 6)\ntable.row(\"ccccccc\", 8.8, 9)\ntable.print()\n```\nwhich yields\n\n```\n+--------------+---------------------------+----------+\n|         col1 | column 2 has a big header | column 3 |\n+--------------+---------------------------+----------+\n|    aaaaaaaaa |                       2.2 |        3 |\n|bbbbbbbbbbbbb |                       5.5 |        6 |\n|      ccccccc |                       8.8 |        9 |\n+--------------+---------------------------+----------+\n```\n***\nOr we can construct a border using the [ANSI box-drawing characters](https://en.wikipedia.org/wiki/Box-drawing_character) which are supported by most terminal\nemulators\n\n```python\ntable = ANSITable(\n        Column(\"col1\"),\n        Column(\"column 2 has a big header\"),\n        Column(\"column 3\"),\n        border=\"thick\"                           # CHANGE\n    )\ntable.row(\"aaaaaaaaa\", 2.2, 3)\ntable.row(\"bbbbbbbbbbbbb\", 5.5, 6)\ntable.row(\"ccccccc\", 8.8, 9)\ntable.print()\n```\nwhich yields\n\n```\n┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓\n┃         col1 ┃ column 2 has a big header ┃ column 3 ┃\n┣━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━┫\n┃    aaaaaaaaa ┃                       2.2 ┃        3 ┃\n┃bbbbbbbbbbbbb ┃                       5.5 ┃        6 ┃\n┃      ccccccc ┃                       8.8 ┃        9 ┃\n┗━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━┛\n```\n_Note: this actually looks better on the console than it does in GitHub markdown._\n\nOther border options include \"thin\", \"rounded\" (thin with round corners) and \"double\".\n\n## Header and column alignment\nWe can change the alignment of data and heading for any column with the alignment flags `\"\u003c\"` (left), \n`\"\u003e\"` (right) and `\"^\"` (centered).\n\n```python\ntable = ANSITable(\n        Column(\"col1\"),\n        Column(\"column 2 has a big header\", colalign=\"^\"),  # CHANGE\n        Column(\"column 3\"),\n        border=\"thick\"\n    )\ntable.row(\"aaaaaaaaa\", 2.2, 3)\ntable.row(\"bbbbbbbbbbbbb\", 5.5, 6)\ntable.row(\"ccccccc\", 8.8, 9)\ntable.print()\n```\nwhich yields\n\n\n```\n┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓\n┃         col1 ┃ column 2 has a big header ┃ column 3 ┃\n┣━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━┫\n┃    aaaaaaaaa ┃            2.2            ┃        3 ┃\n┃bbbbbbbbbbbbb ┃            5.5            ┃        6 ┃\n┃      ccccccc ┃            8.8            ┃        9 ┃\n┗━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━┛\n```\nwhere the data for column 2 has been centered.\n***\nHeading and data alignment for any column can be set independently\n\n```python\ntable = ANSITable(\n        Column(\"col1\", headalign=\"\u003c\"),                      # CHANGE\n        Column(\"column 2 has a big header\", colalign=\"^\"),\n        Column(\"column 3\", colalign=\"\u003c\"),                   # CHANGE\n        border=\"thick\"\n    )\ntable.row(\"aaaaaaaaa\", 2.2, 3)\ntable.row(\"bbbbbbbbbbbbb\", -5.5, 6)\ntable.row(\"ccccccc\", 8.8, -9)\ntable.print()\n```\nyields\n\n```\n┏━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓\n┃          col1 ┃ column 2 has a big header ┃ column 3 ┃\n┣━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━┫\n┃     aaaaaaaaa ┃                       2.2 ┃        3 ┃\n┃ bbbbbbbbbbbbb ┃                      -5.5 ┃        6 ┃\n┃       ccccccc ┃                       8.8 ┃       -9 ┃\n┗━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━┛\n```\nwhere we have left-justified the heading for column 1 and the data for column 3.\n\nWe can easily add a dividing line\n```python\ntable = ANSITable(\n        Column(\"col1\", headalign=\"\u003c\"),\n        Column(\"column 2 has a big header\", colalign=\"^\"),\n        Column(\"column 3\", colalign=\"\u003c\"),\n        border=\"thick\"\n    )\ntable.row(\"aaaaaaaaa\", 2.2, 3)\ntable.row(\"bbbbbbbbbbbbb\", -5.5, 6)\ntable.rule()                                                # CHANGE\ntable.row(\"ccccccc\", 8.8, -9)\ntable.print()\n```\nyields\n\n```\n┏━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓\n┃          col1 ┃ column 2 has a big header ┃ column 3 ┃\n┣━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━┫\n┃     aaaaaaaaa ┃                       2.2 ┃        3 ┃\n┃ bbbbbbbbbbbbb ┃                      -5.5 ┃        6 ┃\n┣━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━┫\n┃       ccccccc ┃                       8.8 ┃       -9 ┃\n┗━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━┛\n```\n\n\n## Color\nIf you have the `colored` package installed then you can set the foreground and\nbackground color and style (bold, reverse, underlined, dim) of the header and column data, as well as the border color.\n\n```python\ntable = ANSITable(\n    Column(\"col1\", headalign=\"\u003c\", colcolor=\"red\", headstyle=\"underlined\"),      # CHANGE\n    Column(\"column 2 has a big header\", colalign=\"^\", colstyle=\"bold\"),      # CHANGE\n    Column(\"column 3\", colalign=\"\u003c\", colbgcolor=\"green\"),                       # CHANGE\n    border=\"thick\", bordercolor=\"blue\"                                          # CHANGE\n)\n\ntable.row(\"aaaaaaaaa\", 2.2, 3)\ntable.row(\"bbbbbbbbbbbbb\", -5.5, 6)                        # CHANGE\ntable.row(\"ccccccc\", 8.8, -9)\ntable.print()\n```\n\nwhich yields\n\n![colored table](https://github.com/petercorke/ansitable/raw/master/figs/colortable.png) \n\nIt is possible to the change the color of a single row of the table, overriding the column\ndefaults, by\n\n```python\n    table.row(\"aaaaaaaaa\", 2.2, 3)\n    table.row(\"bbbbbbbbbbbbb\", 5.5, 6)\n    table.row(\"ccccccc\", 8.8, -9)\n```\n\nwhich yields\n\n![colored table](https://github.com/petercorke/ansitable/raw/master/figs/colortable2.png) \n\nIt is also possible to the change the color of a single cell of the table, overriding the column\nand row defaults, by passing a `Cell` instance\n\n```python\ntable = ANSITable(\"col1\", \"column 2 has a big header\", \"column 3\")\n    table.row(\"aaaaaaaaa\", 2.2, 3)\n    table.row(\"bbbbbbbbbbbbb\", Cell(-5.5, bgcolor=\"blue\"), 6, bgcolor=\"yellow\")  # CHANGE\n    table.row(\"ccccccc\", 8.8, 9)\n    table.print()\n```\nwhich yields\n\n![colored table](https://github.com/petercorke/ansitable/raw/master/figs/colortable3.png) \n\nThe older method (deprecated) of doing this is by prefixing the value with a color enclosed in double angle brackets, for example `\u003c\u003cred\u003e\u003e`.  This does not allow changing the background\ncolor or style of the cell.\n\n```python\ntable = ANSITable(\"col1\", \"column 2 has a big header\", \"column 3\")\n    table.row(\"aaaaaaaaa\", 2.2, 3)\n    table.row(\"\u003c\u003cred\u003e\u003ebbbbbbbbbbbbb\", 5.5, 6)\n    table.row(\"\u003c\u003cblue\u003e\u003eccccccc\", 8.8, 9)\n    table.print()\n```\n\n## All options\n\n### ANSITable\nThese keyword arguments control the styling of the entire table.\n\n| Keyword  | Default | Purpose |\n|----      |----     |----    |\ncolsep | 2 | Gap between columns (in spaces)\noffset | 0 | Gap at start of each row, shifts the table to the left\nborder | no border  | Border style: 'ascii', 'thin', 'thick', 'double'\nbordercolor | |Border color, see [possible values](https://pypi.org/project/colored)\nellipsis | True | Add an ellipsis if a wide column is truncated\nheader | True | Include the column header row\ncolumns | | Specify the number of columns if `header=False` and no header name or `Column` arguments are given\ncolor | True | Enable color \n\n- Color is only possible if the `colored` package is installed\n- If `color` is False then no color escape sequences will be emitted, useful \n  override for tables included in Sphinx documentation.\n\n### Column\nThese keyword arguments control the styling of a single column.\n\n| Keyword  | Default | Purpose |\n|----      |----     |----    |\nfmt | `\"{}\"` | format string for the column value, or a callable that maps the column value to a string\nwidth || maximum column width, excess will be truncated\ncolcolor || Text color, see [possible values](https://pypi.org/project/colored)\ncolbgcolor || Text background color, see [possible values](https://pypi.org/project/colored)\ncolstyle  || Text style: \"bold\", \"underlined\", \"reverse\", \"dim\", \"blink\"\ncolalign | `\"\u003e\"` | Text alignment: `\"\u003e\"` (left), `\"\u003c\"` (right), `\"^\"` (centered)\nheadcolor || Heading text color, see [possible values](https://pypi.org/project/colored)\nheadbgcolor || Heading text background color, see [possible values](https://pypi.org/project/colored)\nheadstyle || Heading text style: \"bold\", \"underlined\", \"reverse\", \"dim\", \"blink\"\nheadalign | `\"\u003e\"` | Heading text alignment: `\"\u003e\"` (left), `\"\u003c\"` (right), `\"^\"` (centered)\n\nNote that many terminal emulators do not support the \"blink\" style.\n\n### Row\nThese keyword arguments control the styling of a single row.\n\n| Keyword  | Default | Purpose |\n|----      |----     |----    |\nfgcolor || Text color, see [possible values](https://pypi.org/project/colored)\nbgcolor || Text background color, see [possible values](https://pypi.org/project/colored)\nstyle  || Text style: \"bold\", \"underlined\", \"reverse\", \"dim\", \"blink\"\n\nRow styling overrides column styling.\n\n### Cell\nThese keyword arguments control the styling of a single cell.\n\n| Keyword  | Default | Purpose |\n|----      |----     |----    |\nfgcolor || Text color, see [possible values](https://pypi.org/project/colored)\nbgcolor || Text background color, see [possible values](https://pypi.org/project/colored)\nstyle  || Text style: \"bold\", \"underlined\", \"reverse\", \"dim\", \"blink\"\n\nCell styling overrides row and column styling.\n\n\n## Render to markup language\n\nNow that you can visualize your data as a beautiful table on the console, you\nmight want the table in a different format to include in a\ndocument or website.  ANSItable supports rendering a table into one of a number of common markup languages.\n\nWe start by creating a simple table\n\n```python\ntable = ANSITable(\"col1\", \"column 2 has a big header\", \"column 3\")\ntable.row(\"aaaaaaaaa\", 2.2, 3)\ntable.row(\"bbbbbbbbbbbbb\", -5.5, 6)\ntable.row(\"ccccccc\", 8.8, -9)\ntable.print()\n```\n\nSupport for alignment and color options depends on the capability of the markup language that is being exported to.\n\n\n### Markdown\n\nThe table can be rendered into Markdown format by\n\n```\ntable.markdown()\n```\nwhich generates\n```\n|          col1 | column 2 has a big header | column 3 |\n| ------------: | ------------------------: | -------: |\n|     aaaaaaaaa |                       2.2 |        3 |\n| bbbbbbbbbbbbb |                      -5.5 |        6 |\n|       ccccccc |                       8.8 |       -9 |\n```\n\nColumn alignment is supported, but MarkDown doesn't allow the header to have different alignment to the data.\n\n\n### HTML\n\nThe table can be rendered into Markdown format by\n\n```\ntable.html()\n```\nwhich generates\n\n```\n\u003ctable style=''\u003e\n  \u003ctr style=''\u003e\n    \u003cth style='text-align:right;'\u003ecol1\u003c/th\u003e\n    \u003cth style='text-align:right;'\u003ecolumn 2 has a big header\u003c/th\u003e\n    \u003cth style='text-align:right;'\u003ecolumn 3\u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr style=''\u003e\n    \u003ctd style='text-align:right;'\u003eaaaaaaaaa\u003c/td\u003e\n    \u003ctd style='text-align:right;'\u003e2.2\u003c/td\u003e\n    \u003ctd style='text-align:right;'\u003e3\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr style=''\u003e\n    \u003ctd style='text-align:right;'\u003ebbbbbbbbbbbbb\u003c/td\u003e\n    \u003ctd style='text-align:right;'\u003e-5.5\u003c/td\u003e\n    \u003ctd style='text-align:right;'\u003e6\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr style=''\u003e\n    \u003ctd style='text-align:right;'\u003eccccccc\u003c/td\u003e\n    \u003ctd style='text-align:right;'\u003e8.8\u003c/td\u003e\n    \u003ctd style='text-align:right;'\u003e-9\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n```\nwhich renders as\n\n\u003ctable style=''\u003e\n  \u003ctr style=''\u003e\n    \u003cth style='text-align:right;'\u003ecol1\u003c/th\u003e\n    \u003cth style='text-align:right;'\u003ecolumn 2 has a big header\u003c/th\u003e\n    \u003cth style='text-align:right;'\u003ecolumn 3\u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr style=''\u003e\n    \u003ctd style='text-align:right;'\u003eaaaaaaaaa\u003c/td\u003e\n    \u003ctd style='text-align:right;'\u003e2.2\u003c/td\u003e\n    \u003ctd style='text-align:right;'\u003e3\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr style=''\u003e\n    \u003ctd style='text-align:right;'\u003ebbbbbbbbbbbbb\u003c/td\u003e\n    \u003ctd style='text-align:right;'\u003e-5.5\u003c/td\u003e\n    \u003ctd style='text-align:right;'\u003e6\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr style=''\u003e\n    \u003ctd style='text-align:right;'\u003eccccccc\u003c/td\u003e\n    \u003ctd style='text-align:right;'\u003e8.8\u003c/td\u003e\n    \u003ctd style='text-align:right;'\u003e-9\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nCSS styling options can be applied to the table, rows and cells.\nThis format supports ANSItable header and column foreground and background color options.\n\n### ReStructedText\n\nThe table can be rendered into reStructedText (ReST) \"simple table\" format by\n\n```\ntable.rest()\n```\nwhich generates\n```\n=============  =========================  ========\n         col1  column 2 has a big header  column 3\n=============  =========================  ========\n    aaaaaaaaa                        2.2         3\nbbbbbbbbbbbbb                       -5.5         6\n      ccccccc                        8.8        -9\n=============  =========================  ========\n```\n\nHeader and column alignment options are not supported in the ReST simple\ntable format.\n\n\n### LaTex\n\nThe table can be rendered into LaTeX format by\n\n```\ntable.latex()\n```\nwhich generates\n```\n\\begin{tabular}{ |r|r|r| }\\hline\n\\multicolumn{1}{|r|}{col1} \u0026 \\multicolumn{1}{|r|}{column 2 has a big header} \u0026 \\multicolumn{1}{|r|}{column 3}\\\\\\hline\\hline\naaaaaaaaa \u0026 2.2 \u0026 3 \\\\\nbbbbbbbbbbbbb \u0026 -5.5 \u0026 6 \\\\\nccccccc \u0026 8.8 \u0026 -9 \\\\\n\\hline\n\\end{tabular}\n```\n\nHeader and column alignment options are supported.\n\n### Wikitable\n\nThe table can be rendered into wikitable markup format, as used for tables in Wikipedia, by\n\n```\ntable.wikitable()\n```\nwhich generates\n```\n{| class=\"wikitable\" col1right col2right col3right\n|-\n!           col1  !!  column 2 has a big header  !!  column 3  \n|-\n|      aaaaaaaaa  ||                        2.2  ||         3  \n|-\n|  bbbbbbbbbbbbb  ||                       -5.5  ||         6  \n|-\n|        ccccccc  ||                        8.8  ||        -9  \n|}\n```\n\nColumn alignment is supported, but wikitable headers are always centred.\n\n### CSV\n\nThe table can be rendered into CSV format by\n\n```\ntable.csv()\n```\nwhich generates\n```\ncol1,column 2 has a big header,column 3\naaaaaaaaa,2.2,3\nbbbbbbbbbbbbb,-5.5,6\nccccccc,8.8,-9\n```\n The delimiter character defaults to comma, but can be set.  \n\nCSV format data can be quickly visualized on the desktop using any spreadsheet program,\nor included in ReST documentation using the `csv-table` directive.\n\n## Pandas integration\n\nPandas is THE tool to use for tabular data so we support conversions in both directions.\n\nTo convert a Pandas DataFrame to an ANSItable is just\n\n```\nimport pandas as pd\n\ndf = pd.DataFrame({\"calories\": [420, 380, 390], \"duration\": [50, 40, 45]})\ntable = ANSITable.Pandas(df, border=\"thin\")\ntable.print()\n\n┌──────────┬──────────┐\n│ calories │ duration │\n├──────────┼──────────┤\n│      420 │       50 │\n│      380 │       40 │\n│      390 │       45 │\n└──────────┴──────────┘\n```\n``Pandas()`` is a static method that acts like a constructor. This is the simplest way to display CSV format data in an ANSItable by using Pandas ``read_csv()`` to load the data into a ``DataFrame``.\n\nTo export an ANSItable as a Pandas DataFrame is simply\n\n```\ntable = ANSITable(\"col1\", \"column 2 has a big header\", \"column 3\")\ntable.row(\"aaaaaaaaa\", 2.2, 3)\ntable.row(\"bbbbbbbbbbbbb\", -5.5, 6)\ntable.row(\"ccccccc\", 8.8, -9)\n\ndf = table.pandas()\nprint(df)\n\n            col1 column_2_has_a_big_header column_3\n0      aaaaaaaaa                       2.2        3\n1  bbbbbbbbbbbbb                      -5.5        6\n2        ccccccc                       8.8       -9\n```\nNote that the column names have been modified, spaces changed to underscores, which\nallows the columns to be accessed as attributes:\n\n```\nprint(df.column_2_has_a_big_header.to_string())\n\n0     2.2\n1    -5.5\n2     8.8\n```\nwhich shows the column as a Pandas `Series` object. This column name-changing behaviour can be disabled by passing ``underscores=False``.\n\n\n# Matrices\n\nPainless creation of nice-looking matrices for Python.\n\n\nWe can create a formatter for NumPy arrays (1D or 2D)\n\n```python\nfrom ansitable import ANSIMatrix\nformatter = ANSIMatrix(style='thick')\n```\n\nand then use it to format a NumPy array\n\n```python\nm = np.random.rand(4,4) - 0.5\nm[0,0] = 1.23456e-14\nformatter.print(m)\n```\n\nyields\n\n```\n┏                                           ┓\n┃ 0         -0.385     -0.106      0.296    ┃\n┃ 0.0432     0.339      0.119     -0.468    ┃\n┃ 0.405     -0.306      0.0165    -0.439    ┃\n┃ 0.203      0.4       -0.499     -0.487    ┃\n┗                                           ┛\n```\n\nwe can also add suffixes\n\n\n```python\nformatter.print(m, suffix_super='T', suffix_sub='3')\n```\n\nyields\n\n```\n┏                                           ┓T\n┃ 0         -0.239      0.186     -0.414    ┃\n┃ 0.49       0.215     -0.0148     0.0529   ┃\n┃ 0.0473     0.0311     0.45       0.394    ┃\n┃-0.192      0.193     -0.455      0.0302   ┃\n┗                                           ┛3\n```\n\nBy default output is printed to the console (stdout) but we can also:\n\n* provide a `file` option to `.print()` to allow writing to a specified output stream, the default is `stdout`.\n* obtain a multi-line string version of the entire table using the `.str()` method\ninstead of `.print()`.\n\nThe formatter takes additional arguments to control the numeric format and to \ncontrol the suppression of very small values.\n\n### ANSIMatrix\nThese keyword arguments control the overall styling and operation of the formatter.\n\n| Keyword  | Default | Purpose |\n|----      |----     |----    |\nstyle | `\"thin\"` | `\"thin\"`, `\"round\"`, `\"thick\"`, `\"double\"`\nfmt | `\"{:\u003c 10.3g}\"` | format for each element\nsquish | True | set small elements to zero\nsquishtol | 100 | elements less than `squishtol * eps` are set to zero\n\n### Formatter\nA formatter takes additional arguments to the styling for a particular call.\n\n| Keyword  | Default | Purpose |\n|----      |----     |----    |\nsuffix_super | `\"\"` | superscript suffix text\nsuffix_sub | `\"\"` | subscript suffix text\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpetercorke%2Fansitable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpetercorke%2Fansitable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpetercorke%2Fansitable/lists"}