有人帮助解释为什么此代码将错误显示为"list index out of range"
吗?
我尝试用文本文件数据绘制图形。
import matplotlib.pyplot as plt
import csv
x,y = [],[]
with open('text.txt','r') as csvfile:
plots = csv.reader(csvfile, delimiter=',')
for row in plots:
x.append(int(row[0]))
y.append(int(row[1]))
plt.legend()
plt.show()
文本文件
0, 1
1, 3
2, 7
3, 5
....
结果
IndexError Traceback (most recent call last)
<ipython-input-5-f3977bc887cc> in <module>()
5 plots = csv.reader(csvfile, delimiter=',')
6 for row in plots:
----> 7 x.append(int(row[0]))
8 y.append(int(row[1]))
9 plt.legend()
IndexError: list index out of range