首页 > 解决方案 > 调用 tabulate TypeError: 'tuple' object is not callable 后出现此错误

问题描述

from tabulate import tabulate

mydata= [('29.16', '30.10', '1', '7')
         ('20.83', '17.60', '2', '5')
         ('12.50', '12.49', '3', '3')
         ('8.33', '9.69', '4', '2')
         ('8.33', '7.92', '5', '2')
         ('8.33', '6.69', '6', '2')
         ('0', '5.80', '7', '0')
         ('8.33', '5.12', '8', '2')
         ('4.17', '4.58', '9', '1')]

header= [('Actual Value', 'Predicted value', 'Leading Digit value', 'Count')
         ]

print(tabulate(mydata, headers=header))

标签: python

解决方案


您的输入有一些错误。您在上面的评论中缺少commas( ,) 。mydata要解决解决方案,您应该更改

mydata= [('29.16', '30.10', '1', '7')
         ('20.83', '17.60', '2', '5')
         ('12.50', '12.49', '3', '3')
         ('8.33', '9.69', '4', '2')
         ('8.33', '7.92', '5', '2')
         ('8.33', '6.69', '6', '2')
         ('0', '5.80', '7', '0')
         ('8.33', '5.12', '8', '2')
         ('4.17', '4.58', '9', '1')]

mydata= [('29.16', '30.10', '1', '7'),
         ('20.83', '17.60', '2', '5'),
         ('12.50', '12.49', '3', '3'),
         ('8.33', '9.69', '4', '2'),
         ('8.33', '7.92', '5', '2'),
         ('8.33', '6.69', '6', '2'),
         ('0', '5.80', '7', '0'),
         ('8.33', '5.12', '8', '2'),
         ('4.17', '4.58', '9', '1')]

推荐阅读