To use the Python API, add this directory (.../fixfmt/python/
) to your
PYTHONPATH
.
The Python API is a wrapper around the C++ API. For example,
>>> import fixfmt
>>> fmt = fixfmt.Bool()
>>> fmt(True)
'true '
>>> fmt(False)
'false'
>>> fmt = fixfmt.String(10)
>>> fmt("testing")
'testing '
>>> fmt("Hello, world!")
'Hello, wo…'
>>> fmt = fixfmt.Number(3, 3)
>>> fmt(math.pi)
' 3.142'
fixfmt.pandas.print_dataframe()
provides a replacement for Pandas's built-in
dataframe formatting routines.
>>> print(df)
label value
0 pi 3.141590
1 negative one -1.000000
2 Euler's number 2.718282
>>> fixfmt.pandas.print_dataframe(df)
| label value
==== | ============== ==========
0 | pi 3.1415900
1 | negative one -1.0000000
2 | Euler's number 2.7182818
This function takes a second configuration argument, which may be customized to adjust most aspects of the formatting. For example, an alternate configuration uses Unicode box drawing characters to surround the table.
>>> fixfmt.pandas.print_dataframe(df, fixfmt.table.UNICODE_BOX_CFG)
┌──────╥────────────────┬────────────┐
│ ║ label │ value │
├──────╫────────────────┼────────────┤
│ 0 ║ pi │ 3.1415900 │
│ 1 ║ negative one │ -1.0000000 │
│ 2 ║ Euler's number │ 2.7182818 │
└──────╨────────────────┴────────────┘