python-tabulate icon indicating copy to clipboard operation
python-tabulate copied to clipboard

bug: Error when I print a table with colored data

Open Adamou02 opened this issue 2 years ago • 1 comments

Description

I colorized my float with basic Python feature :

row_data["reference"] = "\033[31m{}\033[0m".format(value_data_ref)

After few manipulations, I put these floats in a column of my Pandas Dataframe.

data_results = pd.DataFrame(data_results)
print(data_results)

Works well :

image Header are not well positioned, but Pd dataframe works well.

Then, I print the table with tabulate module.

print(tabulate(data_results, headers="keys", tablefmt="fancy_grid", maxcolwidths=30, showindex=False))

Error occurs here :

ValueError: could not convert string to float: '\x1b[31m965.3344\x1b[0m'

Reproduce

Use a column with formated data. In my case this row :

row_data["reference"] = "\033[31m{}\033[0m".format(value_data_ref)

Expected behavior

image

With numbers in column "reference" print in red.

Context

  • Python version : 3.10

Adamou02 avatar Aug 30 '23 14:08 Adamou02

This PR would solve my problem ! (#135)

Adamou02 avatar Aug 30 '23 14:08 Adamou02