astanin / python-tabulate

Pretty-print tabular data in Python, a library and a command-line utility. Repository migrated from bitbucket.org/astanin/python-tabulate.
https://pypi.org/project/tabulate/
MIT License
2.1k stars 163 forks source link

Integer DataFrame columns are erroneously converted to `float` #240

Open bluenote10 opened 1 year ago

bluenote10 commented 1 year ago

Apparently integer DataFrame columns are implicitly converted to floats, which makes proper integer formatting impossible, and worse, passing e.g. `floatfmt=".6f" will lead to non-sense formatting of integer columns. Here is a minimal example:

import pandas as pd
import tabulate

df = pd.DataFrame({"int_col": [123456789], "float_col": 1.23456789})

print(tabulate.tabulate(df, headers="keys", intfmt=","))

Current output:

        int_col    float_col
--  -----------  -----------
 0  1.23457e+08      1.23457

Expected output:

         int_col    float_col
--  ------------  -----------
 0   12,345,789      1.23457

Tabulate version: 0.9.0

bluenote10 commented 1 year ago

FYI as a work-around one can use df.to_dict("records").

Oli4 commented 1 year ago

I have the same issue for large integers with tabulate version 0.9.0