Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python通过列将数据从数组添加到prettytable_Python_Python 3.x_Prettytable - Fatal编程技术网

Python通过列将数据从数组添加到prettytable

Python通过列将数据从数组添加到prettytable,python,python-3.x,prettytable,Python,Python 3.x,Prettytable,我创建了一个满是数字的数组。我想使用add_列将数组中的数据添加到prettytable中 number=[1,2,3,4,5,6,7,8,9,.....,100] 我希望漂亮表格的输出如下所示 +-----------+------+------------+-----------------+ | Number |1 | 2 | 3 | 4 | ..... | +-----------+------+------------+--------------

我创建了一个满是数字的数组。我想使用add_列将数组中的数据添加到prettytable中

number=[1,2,3,4,5,6,7,8,9,.....,100]
我希望漂亮表格的输出如下所示

+-----------+------+------------+-----------------+
| Number  |1 | 2 | 3 | 4 | .....                  |
+-----------+------+------------+-----------------+
我的代码如下所示

from prettytable import PrettyTable

x = PrettyTable()
x.add_column(["number", print(number)])
print(x)
当我运行python脚本时,它生成了一个错误

TypeError:add_column()缺少1个必需的位置参数:“column”


如何实现这一点?

您应该像这样使用add raw,如果 您需要将“number”添加为应添加到列表中的文本

number=['number',1,2,3,4,5,6,7,8,9]

from prettytable import PrettyTable
x = PrettyTable()
x.add_row(number)
print(x)
输出:

+---------+---------+---------+---------+---------+---------+---------+---------+---------+----------+
| Field 1 | Field 2 | Field 3 | Field 4 | Field 5 | Field 6 | Field 7 | Field 8 | Field 9 | Field 10 |
+---------+---------+---------+---------+---------+---------+---------+---------+---------+----------+
|  number |    1    |    2    |    3    |    4    |    5    |    6    |    7    |    8    |    9     |
+---------+---------+---------+---------+---------+---------+---------+---------+---------+----------+

是否可以删除标题字段?我指的是字段1,字段2,字段3,因为我知道你不能