@@ -53,7 +53,7 @@ pip install tabulate
5353Build status
5454------------
5555
56- [ ![ Build status ] ( https://circleci .com/gh/ astanin/python-tabulate. svg?style=svg )] ( https://circleci .com/gh/ astanin/python-tabulate/tree/master ) [ ![ Build status] ( https://ci.appveyor.com/api/projects/status/8745yksvvol7h3d7/branch/master?svg=true )] ( https://ci.appveyor.com/project/astanin/python-tabulate/branch/master )
56+ [ ![ python-tabulate ] ( https://github .com/astanin/python-tabulate/actions/workflows/tabulate.yml/badge. svg )] ( https://github .com/astanin/python-tabulate/actions/workflows/tabulate.yml ) [ ![ Build status] ( https://ci.appveyor.com/api/projects/status/8745yksvvol7h3d7/branch/master?svg=true )] ( https://ci.appveyor.com/project/astanin/python-tabulate/branch/master )
5757
5858Library usage
5959-------------
@@ -81,7 +81,7 @@ The following tabular data types are supported:
8181- list of lists or another iterable of iterables
8282- list or another iterable of dicts (keys as columns)
8383- dict of iterables (keys as columns)
84- - list of dataclasses (Python 3.7+ only, field names as columns)
84+ - list of dataclasses (field names as columns)
8585- two-dimensional NumPy array
8686- NumPy record arrays (names as columns)
8787- pandas.DataFrame
@@ -121,10 +121,22 @@ dictionaries or named tuples:
121121``` pycon
122122>>> print (tabulate({" Name" : [" Alice" , " Bob" ],
123123... " Age" : [24 , 19 ]}, headers= " keys" ))
124- Age Name
125- ----- ------
126- 24 Alice
127- 19 Bob
124+ Name Age
125+ ------ -----
126+ Alice 24
127+ Bob 19
128+ ```
129+
130+ When data is a list of dictionaries, a dictionary can be passed as ` headers `
131+ to replace the keys with other column labels:
132+
133+ ``` pycon
134+ >>> print (tabulate([{1 : " Alice" , 2 : 24 }, {1 : " Bob" , 2 : 19 }],
135+ ... headers= {1 : " Name" , 2 : " Age" }))
136+ Name Age
137+ ------ -----
138+ Alice 24
139+ Bob 19
128140```
129141
130142### Row Indices
@@ -323,6 +335,22 @@ corresponds to the `pipe` format without alignment colons:
323335╘════════╧═══════╛
324336```
325337
338+ ` colon_grid ` is similar to ` grid ` but uses colons only to define
339+ columnwise content alignment , without whitespace padding,
340+ similar the alignment specification of Pandoc ` grid_tables ` :
341+
342+ >>> print(tabulate([["spam", 41.9999], ["eggs", "451.0"]],
343+ ... ["strings", "numbers"], "colon_grid",
344+ ... colalign=["right", "left"]))
345+ +-----------+-----------+
346+ | strings | numbers |
347+ +==========:+:==========+
348+ | spam | 41.9999 |
349+ +-----------+-----------+
350+ | eggs | 451 |
351+ +-----------+-----------+
352+
353+
326354` outline ` is the same as the ` grid ` format but doesn't draw lines between rows:
327355
328356 >>> print(tabulate(table, headers, tablefmt="outline"))
@@ -727,13 +755,8 @@ column, in which case every column may have different number formatting:
727755### Text formatting
728756
729757By default, ` tabulate ` removes leading and trailing whitespace from text
730- columns. To disable whitespace removal, set the global module-level flag
731- ` PRESERVE_WHITESPACE ` :
732-
733- ``` python
734- import tabulate
735- tabulate.PRESERVE_WHITESPACE = True
736- ```
758+ columns. To disable whitespace removal, pass ` preserve_whitespace=True ` .
759+ Older versions of the library used a global module-level flag PRESERVE_WHITESPACE.
737760
738761### Wide (fullwidth CJK) symbols
739762
@@ -1036,21 +1059,19 @@ simply joining lists of values with a tab, comma, or other separator.
10361059
10371060At the same time, ` tabulate ` is comparable to other table
10381061pretty-printers. Given a 10x10 table (a list of lists) of mixed text and
1039- numeric data, ` tabulate ` appears to be slower than ` asciitable ` , and
1040- faster than ` PrettyTable ` and ` texttable ` The following mini-benchmark
1041- was run in Python 3.9.13 on Windows 10:
1042-
1043- ================================= ========== ===========
1044- Table formatter time, μs rel. time
1045- ================================= ========== ===========
1046- csv to StringIO 12.5 1.0
1047- join with tabs and newlines 14.6 1.2
1048- asciitable (0.8.0) 192.0 15.4
1049- tabulate (0.9.0) 483.5 38.7
1050- tabulate (0.9.0, WIDE_CHARS_MODE) 637.6 51.1
1051- PrettyTable (3.4.1) 1080.6 86.6
1052- texttable (1.6.4) 1390.3 111.4
1053- ================================= ========== ===========
1062+ numeric data, ` tabulate ` appears to be faster than ` PrettyTable ` and ` texttable ` .
1063+ The following mini-benchmark was run in Python 3.11.9 on Windows 11 (x64):
1064+
1065+ ================================== ========== ===========
1066+ Table formatter time, μs rel. time
1067+ ================================== ========== ===========
1068+ join with tabs and newlines 6.3 1.0
1069+ csv to StringIO 6.6 1.0
1070+ tabulate (0.10.0) 249.2 39.3
1071+ tabulate (0.10.0, WIDE_CHARS_MODE) 325.6 51.4
1072+ texttable (1.7.0) 579.3 91.5
1073+ PrettyTable (3.11.0) 605.5 95.6
1074+ ================================== ========== ===========
10541075
10551076
10561077Version history
@@ -1074,33 +1095,33 @@ To run tests on all supported Python versions, make sure all Python
10741095interpreters, ` pytest ` and ` tox ` are installed, then run ` tox ` in the root
10751096of the project source tree.
10761097
1077- On Linux ` tox ` expects to find executables like ` python3.7 ` , ` python3.8 ` etc.
1078- On Windows it looks for ` C:\Python37 \python.exe ` , ` C:\Python38 \python.exe ` etc. respectively.
1098+ On Linux ` tox ` expects to find executables like ` python3.11 ` , ` python3.12 ` etc.
1099+ On Windows it looks for ` C:\Python311 \python.exe ` , ` C:\Python312 \python.exe ` etc. respectively.
10791100
10801101One way to install all the required versions of the Python interpreter is to use [ pyenv] ( https://github.com/pyenv/pyenv ) .
10811102All versions can then be easily installed with something like:
10821103
1083- pyenv install 3.7.12
1084- pyenv install 3.8.12
1104+ pyenv install 3.11.7
1105+ pyenv install 3.12.1
10851106 ...
10861107
10871108Don't forget to change your ` PATH ` so that ` tox ` knows how to find all the installed versions. Something like
10881109
10891110 export PATH="${PATH}:${HOME}/.pyenv/shims"
10901111
10911112To test only some Python environments, use ` -e ` option. For example, to
1092- test only against Python 3.7 and Python 3.10 , run:
1113+ test only against Python 3.11 and Python 3.12 , run:
10931114
10941115``` shell
1095- tox -e py37,py310
1116+ tox -e py311,py312
10961117```
10971118
10981119in the root of the project source tree.
10991120
11001121To enable NumPy and Pandas tests, run:
11011122
11021123``` shell
1103- tox -e py37 -extra,py310 -extra
1124+ tox -e py311 -extra,py312 -extra
11041125```
11051126
11061127(this may take a long time the first time, because NumPy and Pandas will
@@ -1133,8 +1154,9 @@ endolith, Dominic Davis-Foster, pavlocat, Daniel Aslau, paulc,
11331154Felix Yan, Shane Loretz, Frank Busse, Harsh Singh, Derek Weitzel,
11341155Vladimir Vrzić, 서승우 (chrd5273), Georgy Frolov, Christian Cwienk,
11351156Bart Broere, Vilhelm Prytz, Alexander Gažo, Hugo van Kemenade,
1136- jamescooke, Matt Warner, Jérôme Provensal, Kevin Deldycke,
1157+ jamescooke, Matt Warner, Jérôme Provensal, Michał Górny, Kevin Deldycke,
11371158Kian-Meng Ang, Kevin Patterson, Shodhan Save, cleoold, KOLANICH,
11381159Vijaya Krishna Kasula, Furcy Pin, Christian Fibich, Shaun Duncan,
1139- Dimitri Papadopoulos, Élie Goudout.
1140-
1160+ Dimitri Papadopoulos, Élie Goudout, Racerroar888, Phill Zarfos,
1161+ Keyacom, Andrew Coffey, Arpit Jain, Israel Roldan, ilya112358,
1162+ Dan Nicholson, Frederik Scheerer, cdar07 (cdar), Racerroar888.
0 commit comments