0
我想繪製一個帶有texttable的表格。我有這樣一段代碼安排表的內容:texttable繪製更改內容的格式
def get_int_avg_pre(r_list, p_list):
li = []
recall_list = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
for recall in recall_list:
r_ind = 0
for i in r_list:
if float(i)/100 >= recall:
r_ind = r_list.index(i)
break
pre = max(p_list[r_ind:])
li.append([str(recall), "{:.2f}".format(float(pre)/100)])
return li
def print_logs(qs, rs):
t = Texttable()
inter_val = get_int_avg_pre(r_list, p_list)
printed_list = [['Recall', 'Interpolated Precision']]
for el in inter_val:
printed_list.append(el)
t.add_rows(printed_list)
print t.draw()
我跳過一些地方,你看到的,因爲它們是不相關的我的問題。用這個腳本,表格內容不是我想要的格式。輸出值在下面,我可以看到printed_list中的確切值。有人能幫我弄清楚我做錯了什麼嗎?
printed_list:
[['Recall', 'Interpolated Precision'], ['0.0', '1.00'], ['0.1', '1.00'], ['0.2', '1.00'], ['0.3', '0.50'], ['0.4', '0.50'], ['0.5', '0.50'], ['0.6', '0.38'], ['0.7', '0.38'], ['0.8', '0.36'], ['0.9', '0.36'], ['1.0', '0.36']]
表: