我需要帮助编写一个程序,该程序从文本文件中读取大约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到了柱状图,快挂 –