使用tabulate库需先引用tabulate
import tabulate
tabulate.tabulate(tabular_data, headers=(), tablefmt='simple', floatfmt='g', \
numalign='decimal', stralign='left', missingval='',\
showindex='default', disable_numparse=False, \
colalign=None)
因本人能力有限仅介绍以下几个简单的基本函数
print(tabulate.tabulate([[1, 2.34], [-56, "8.999"], ["2", "10001"]]))
>>>
--- ---------
1 2.34
-56 8.999
2 10001
--- ---------
在没有输入其他属性时,会使用默认方式输出数据
print(tabulate.tabulate([[1,2],[1, 2.34], [-56, "8.999"], ["2", "10001"]],headers = "firstrow"))
>>>
1 2
--- ---------
1 2.34
-56 8.999
2 10001
headers = firstrow表示用data的第一排数据作为数据头
3. tablefmt=‘simple’ 输出表格边框的“样式”
print(tabulate.tabulate([[1,2],[1, 2.34], [-56, "8.999"], ["2", "10001"]],headers = "firstrow",tablefmt = "simple"))
>>>
1 2
--- ---------
1 2.34
-56 8.999
2 10001
与上一个代码一样是因为tablefmt默认为simple
4. showindex=‘default’ 显示行号