python中的表模块似乎更倾向于处理行:
>>> from tabulate import tabulate
>>> col0 = ["age","sex","location"]
>>> col1 = ["twenty", "male", "mars"]
>>> print(tabulate([col0,col1]))
------ ---- --------
age sex location
twenty male mars
------ ---- --------由于数据排列在列中,所以我想看到:
-------- ------
age twenty
sex male
location mars
-------- ------在不复制数据的情况下,我如何做到这一点?
我有一个解决方案,在输入要表的数据之前,复制一个浪费的副本。
发布于 2022-03-18 18:58:21
通过使用zip将两个列表组合成列表,这是可以完成的。
>>> from tabulate import tabulate
>>> col0 = ["age","sex","location"]
>>> col1 = ["twenty", "male", "mars"]
>>> print(tabulate(list(zip(col0,col1))))
-------- ------
age twenty
sex male
location mars
-------- ------https://stackoverflow.com/questions/71531978
复制相似问题