I know that I\'ve seen some example somewhere before but for the life of me I cannot find it when googling around.
I have some rows of data:
data = [[1,2
I recently used prettytable
for rendering a nice ASCII table. It's similar to the postgres CLI output.
import pandas as pd
from prettytable import PrettyTable
data = [[1,2,3],[4,5,6],[7,8,9]]
df = pd.DataFrame(data, columns=['one', 'two', 'three'])
def generate_ascii_table(df):
x = PrettyTable()
x.field_names = df.columns.tolist()
for row in df.values:
x.add_row(row)
print(x)
return x
generate_ascii_table(df)
Output:
+-----+-----+-------+
| one | two | three |
+-----+-----+-------+
| 1 | 2 | 3 |
| 4 | 5 | 6 |
| 7 | 8 | 9 |
+-----+-----+-------+