@@ -53,7 +53,7 @@ pip install tabulate
53
53
Build status
54
54
------------
55
55
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 )
57
57
58
58
Library usage
59
59
-------------
@@ -81,7 +81,7 @@ The following tabular data types are supported:
81
81
- list of lists or another iterable of iterables
82
82
- list or another iterable of dicts (keys as columns)
83
83
- 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)
85
85
- two-dimensional NumPy array
86
86
- NumPy record arrays (names as columns)
87
87
- pandas.DataFrame
@@ -121,10 +121,22 @@ dictionaries or named tuples:
121
121
``` pycon
122
122
>>> print (tabulate({" Name" : [" Alice" , " Bob" ],
123
123
... " 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
128
140
```
129
141
130
142
### Row Indices
@@ -323,6 +335,22 @@ corresponds to the `pipe` format without alignment colons:
323
335
╘════════╧═══════╛
324
336
```
325
337
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
+
326
354
` outline ` is the same as the ` grid ` format but doesn't draw lines between rows:
327
355
328
356
>>> print(tabulate(table, headers, tablefmt="outline"))
@@ -727,13 +755,8 @@ column, in which case every column may have different number formatting:
727
755
### Text formatting
728
756
729
757
By 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.
737
760
738
761
### Wide (fullwidth CJK) symbols
739
762
@@ -1036,21 +1059,19 @@ simply joining lists of values with a tab, comma, or other separator.
1036
1059
1037
1060
At the same time, ` tabulate ` is comparable to other table
1038
1061
pretty-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
+ ================================== ========== ===========
1054
1075
1055
1076
1056
1077
Version history
@@ -1074,33 +1095,33 @@ To run tests on all supported Python versions, make sure all Python
1074
1095
interpreters, ` pytest ` and ` tox ` are installed, then run ` tox ` in the root
1075
1096
of the project source tree.
1076
1097
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.
1079
1100
1080
1101
One way to install all the required versions of the Python interpreter is to use [ pyenv] ( https://github.com/pyenv/pyenv ) .
1081
1102
All versions can then be easily installed with something like:
1082
1103
1083
- pyenv install 3.7.12
1084
- pyenv install 3.8.12
1104
+ pyenv install 3.11.7
1105
+ pyenv install 3.12.1
1085
1106
...
1086
1107
1087
1108
Don't forget to change your ` PATH ` so that ` tox ` knows how to find all the installed versions. Something like
1088
1109
1089
1110
export PATH="${PATH}:${HOME}/.pyenv/shims"
1090
1111
1091
1112
To 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:
1093
1114
1094
1115
``` shell
1095
- tox -e py37,py310
1116
+ tox -e py311,py312
1096
1117
```
1097
1118
1098
1119
in the root of the project source tree.
1099
1120
1100
1121
To enable NumPy and Pandas tests, run:
1101
1122
1102
1123
``` shell
1103
- tox -e py37 -extra,py310 -extra
1124
+ tox -e py311 -extra,py312 -extra
1104
1125
```
1105
1126
1106
1127
(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,
1133
1154
Felix Yan, Shane Loretz, Frank Busse, Harsh Singh, Derek Weitzel,
1134
1155
Vladimir Vrzić, 서승우 (chrd5273), Georgy Frolov, Christian Cwienk,
1135
1156
Bart 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,
1137
1158
Kian-Meng Ang, Kevin Patterson, Shodhan Save, cleoold, KOLANICH,
1138
1159
Vijaya 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