Search code examples
pythontabulate

I want to print a tabulated list using tabulate, but gives me error


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"]))

ERROR IS FIXED!

But now asking to have the right column be tabulated on right hand side just like the values.


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

Using Python 3.8 running on Spyder IDE

Thank you in advance for the help!
**recently edited --> new question!


Solution

  • 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"]))