在 Python 中打印表格数据

编程入门 行业动态 更新时间:2024-10-27 04:25:33
本文介绍了在 Python 中打印表格数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

在 Python 中打印表格数据的最佳方法是什么?假设数据在 2D 列表中,我想创建一个外观漂亮的表格.我实际拥有的是一个字典列表,我想根据字典中的值打印一个交集.类似的东西

What's the best way to print tabular data in Python? Say the data is in a 2D list and I want to create a smart looking table. What I actually have is a list of dictionaries and I want to print an intersection depending on values in the dictionaries. Something like

for val1 in my_dict:
   for val2 in my_dict:
    if val1['a'] > val2['a']:
      print 'x'

但是每列都是固定宽度的.Writter 和 formatter 类似乎是可能的领域,但与 Perl 的格式化程序相比,使用起来仍然很复杂.

but in such a way that each column is fixed width. Writter and formatter classes seem like something in the realm of possibility, but still look complex to use when compared to, say, Perl's formatter.

是否有任何现有的实现,还是我必须自己编写?

Are there any existing implementations or do I have to write my own?

推荐答案

你知道PyPi?

DataGrid 和 PrettyTable 似乎是我通过简短搜索找到的两个不错的选择.在将数据发送到提供的例程之前,您可能必须以您想要的格式组合数据(当您的条件为真时,使用x"表示).

DataGrid and PrettyTable seem like two good alternatives I found with a brief search. You may have to assemble the data in the format you want it (with "x" for when your condition is true) before sending it to the routines provided.

这篇关于在 Python 中打印表格数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 10:47:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1408785.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表格   数据   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!