I have a Pandas Dataframe generated from a database, which has data with mixed encodings. For example:
+----+-------------------------+----------+-----------
I recommend python-tabulate library for generating ascii-tables. The library supports pandas.DataFrame
as well.
Here is how to use it:
from pandas import DataFrame
from tabulate import tabulate
df = DataFrame({
"weekday": ["monday", "thursday", "wednesday"],
"temperature": [20, 30, 25],
"precipitation": [100, 200, 150],
}).set_index("weekday")
print(tabulate(df, tablefmt="pipe", headers="keys"))
Output:
| weekday | temperature | precipitation |
|:----------|--------------:|----------------:|
| monday | 20 | 100 |
| thursday | 30 | 200 |
| wednesday | 25 | 150 |