Sample data: Rakuten recipe category
from tabulate import tabulate
import pandas as pd
from pprint import pprint
df = pd.read_csv('small_category.csv', encoding='utf-8-sig')
br = '\n'
print(br + 'print'.center(20, '=') + br)
print(df.head())
print(br + 'pprint'.center(20, '=') + br)
pprint(df.head())
print(br + 'tabulate psql'.center(20, '=') + br)
print(tabulate(df.head(), headers='keys',
tablefmt='psql',
numalign='right',
stralign='left', showindex=False))
print(br + 'tabulate simple'.center(20, '=') + br)
print(tabulate(df.head(), headers='keys',
tablefmt='simple',
numalign='right',
stralign='left', showindex=False))
----------output----------
=======print========
Id Type mediumId largeId Name
0 50 small 66 10 Sausage wiener
1 1491 small 67 10 Prosciutto
2 1492 small 67 10 chicken ham
3 321 small 67 10 Other hams
4 49 small 68 10 bacon
=======pprint=======
Id Type mediumId largeId Name
0 50 small 66 10 Sausage wiener
1 1491 small 67 10 Prosciutto
2 1492 small 67 10 chicken ham
3 321 small 67 10 Other hams
4 49 small 68 10 bacon
===tabulate psql====
+------+--------+------------+-----------+-------------+
| Id | Type | mediumId | largeId | Name |
|------+--------+------------+-----------+-------------|
| 50 | small | 66 | 10 |Sausage wiener|
| 1491 | small | 67 | 10 |Raw ham|
| 1492 | small | 67 | 10 |chicken ham|
| 321 | small | 67 | 10 |Other ham|
| 49 | small | 68 | 10 |bacon|
+------+--------+------------+-----------+-------------+
==tabulate simple===
Id Type mediumId largeId Name
---- ------ ---------- --------- -----------
50 small 66 10 sausage wiener
1491 small 67 10 Prosciutto
1492 small 67 10 chicken ham
321 small 67 10 Other ham
49 small 68 10 bacon
Recommended Posts