@ Imm,假設你的第一個
tableA.column_headers =
是你想要的(4項),你有4項5個陣列要添加到表中爲行則可能需要的程序simplier:
from beautifultable import BeautifulTable
tableA = BeautifulTable()
tableA.column_headers = ["possible Inflow", "prob", "possibleinlow * prob", "d12p"]
data = [['a', 1, 2, 2], [4.0, 3.0, 3.0, 2.0], [2.0, 4.0, 1.0, 4.0],\
[8., 12., 3., 8.], [ 1458., 3136., 784., 3364.]]
for i in range(len(data)):
tableA.append_row(data[i])
print(tableA)
...產生:
+-----------------+------+----------------------------------------------+------+
| possible Inflow | prob | possibleinlow * prob | d12p |
+-----------------+------+----------------------------------------------+------+
| a | 1 | 2 | 2 |
+-----------------+------+----------------------------------------------+------+
| 4 | 3 | 3 | 2 |
+-----------------+------+----------------------------------------------+------+
| 2 | 4 | 1 | 4 |
+-----------------+------+----------------------------------------------+------+
| 8 | 12 | 3 | 8 |
+-----------------+------+----------------------------------------------+------+
| 1458 | 3136 | 784 | 3364 |
+-----------------+------+----------------------------------------------+------+
如果你不是想用第二
tabelA.column_headers =
線和您的數據的列信息組,則只是簡單地使用的BeautifulTable的列方法之一。
from beautifultable import BeautifulTable
tableA = BeautifulTable()
columnHeaders = ["inputs", "possible Inflow", "prob", "possibleinlow * prob", "d12p"]
data = [['a', 1, 2, 2], [4.0, 3.0, 3.0, 2.0], [2.0, 4.0, 1.0, 4.0],\
[8., 12., 3., 8.], [1458., 3136., 784., 3364.]]
for i in range(len(columnHeaders)):
tableA.insert_column(i, columnHeaders[i], data[i])
print(tableA)
...主要生產:
+--------+------------------------+------+------------------------------+------+
| inputs | possible Inflow | prob | possibleinlow * prob | d12p |
+--------+------------------------+------+------------------------------+------+
| a | 4 | 2 | 8 | 1458 |
+--------+------------------------+------+------------------------------+------+
| 1 | 3 | 4 | 12 | 3136 |
+--------+------------------------+------+------------------------------+------+
| 2 | 3 | 1 | 3 | 784 |
+--------+------------------------+------+------------------------------+------+
| 2 | 2 | 4 | 8 | 3364 |
+--------+------------------------+------+------------------------------+------+
添加一些打印線可以幫助理解的事情。 乾杯!
舒馬克我實際上想要垂直排列它們 – Imm