我需要幫助編寫一個程序,該程序從文本文件中讀取大約300行,並從特定分配(A1列)獲取分數,然後使用該分配中的分數繪製直方圖快掛。使用python和quickdraw繪製直方圖
ID , Last, First, Lecture, Tutorial, A1, A2, A3, A4, A5
8959079, Moore, Maria, L01, T03, 9.0, 8.5, 8.5, 10.0, 8.5
4295498, Taylor, John, L00, T04, 10.0, 6.5, 8.5, 9.5, 7.0
9326386, Taylor, David, L00, T00, 9.5, 8.0, 8.0, 9.0, 10.0
7223234, Taylor, James, L01, T03, 8.5, 5.5, 10.0, 0.0, 0.5
7547838, Miller, Robert, L01, T09, 7.0, 8.0, 8.5, 10.0, 0.5
0313453, Lee, James, L01, T01, 10.0, 0.5, 8.0, 7.0, 5.0
3544072, Lee, Helen, L00, T03, 10.0, 9.0, 7.0, 9.0, 8.5
到目前爲止,我有從文件(A1)中提取的成績,並把它變成一個列表,然後創建另一個計數一定品位的許多事件如何發生的代碼。我現在有麻煩了,現在使用這個列表並輸入到quickdraw繪製直方圖?
def file():
file = open('sample_input_1.txt', 'r')
col = [] data = file.readlines()
for i in range(1,len(data)-1):
col.append(int(float(data[i].split(',')[5])))
return col
def hist(col):
grades = []
for i in range(11):
grades.append(0)
for i in (col):
grades[i] += 1
return grades
col = file()
grades = hist(col)
print(col)
print(grades)
您需要發佈一些代碼,還有一個更具體的問題 - 是否有錯誤?你看到什麼與你的期望不符? – thegrinner
DEF文件(): \t文件=打開( 'sample_input_1.txt', 'R') \t COL = [] \t數據= file.readlines() \t對於i在範圍(1,LEN(數據) -1): \t \t col.append(INT(浮動(數據[I] .split( '')[5]))) \t返回COL DEF HIST(COL):\t \t \t 等級= [] \t對於i在範圍(11): \t \t grades.append(0) \t對於i在(COL): \t \t等級[I] + = 1個\t \t返回等級 \t COL =文件() 等級= HIST(COL) 打印(COL) 打印(等級) –
這就是到目前爲止我的代碼的廣告即時知道如何從等級列表中的數據DISPLY到了柱狀圖,快掛 –