4

I am using tabulate 0.75 to generate LaTeX tables. The function tabulate which generates my tables has a built-in function to format the input. But I want to define the amount of decimals for every column itself. For e.g.

a      b
18.12  16
17.47  15

This is the built-in function (floatfmt=".2f") which works perfectly - but it acts on every column the same.

tabulate(tables[i], headers[i], numalign="center", tablefmt="latex_booktabs", floatfmt=".2f")

I am getting my data via

tables = [(list(zip(
                unumpy.nominal_values(dt),
                unumpy.nominal_values(U),
                unumpy.nominal_values(I),
                unumpy.nominal_values(E),
                unumpy.std_devs(E)))), ............and so on

I am using ufloat for my lists

array123 = ufloat(nominalvalues, errors)

very often because it makes handling with errors pretty easy. Does anyone know a simple way to format?

"{:.2f}".format(unumpy.nominal_values(E))
TypeError: non-empty format string passed to object.__format__

This doesnt work.

Thanks in advance.

Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186
lrsp
  • 1,213
  • 10
  • 18

1 Answers1

7

From the documentation:

floatfmt argument can be a list or a tuple of format strings, one per column, in which case every column may have different number formatting::

>>> print tabulate([[0.12345, 0.12345, 0.12345]], floatfmt=(".1f", ".3f"))
--- ----- -------
0.1 0.123 0.12345
--- ----- -------

That should make your code a little neater.

castle-bravo
  • 1,389
  • 15
  • 34