【问题标题】:I want to print a tabulated list using tabulate, but gives me error我想使用 tabulate 打印一个列表,但给了我错误
【发布时间】:2020-11-10 18:34:02
【问题描述】:
list02 = [[101, 75.00, 69.31, 19, 'FAR'],
          [102, 75.00, 68.71, 19, 'FAR'],
          [103, 75.00, 67.55, 18, 'MIA'],
          [104, 75.00, 65.41, 18, 'FSD'],
          [105, 74.00, 64.39, 18, 'FAR'],
          [106, 73.00, 63.36, 17, 'CLT']]

from tabulate import tabulate

print(tabulate(list02, headers=["Line#", "Credit", "Hrs", "Days Off", "ARP"]))

错误已修复!

但现在要求将右列像值一样列在右侧。


Line#    Credit    Hrs          Days Off  Overnight
-------  --------  ---------  ----------  -----------
    101        75      69.31          19  FAR
    102        75      68.71          19  FAR
    103        75      67.55          18  MIA
    104        75      65.41          18  FSD
    105        74      64.39          18  FAR
    106        73      63.36          17  CLT

使用在 Spyder IDE 上运行的 Python 3.8

提前感谢您的帮助!
**最近编辑过 --> 新问题!

【问题讨论】:

  • 您在每个子列表之间漏掉了一个逗号
  • 因为您用逗号编辑了答案。我相信你现在不会有任何问题
  • 谢谢!!!是的,修复了它,并且必须使用以下命令安装表格: conda install -c conda-forge tabulate

标签: python tabulate


【解决方案1】:
list02 = [[101, 75.00, 69.31, 19, 'FAR'],
          [102, 75.00, 68.71, 19, 'FAR'],
          [103, 75.00, 67.55, 18, 'MIA'],
          [104, 75.00, 65.41, 18, 'FSD'],
          [105, 74.00, 64.39, 18, 'FAR'],
          [106, 73.00, 63.36, 17, 'CLT']]

from tabulate import tabulate

print(tabulate(list02, headers=["Line#", "Credit", "Hrs", "Days Off", "ARP"]))

【讨论】:

  • 感谢您抽出时间回答!我必须通过以下方式实际安装表格: conda install -c conda-forge tabulate
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-20
  • 2021-05-18
  • 1970-01-01
  • 2015-07-21
  • 2021-09-11
  • 1970-01-01
相关资源
最近更新 更多