我需要修理什么?
ValueError Traceback (most recent call last)
<ipython-input-53-56f3e9d938be> in <module>()
11 plots=csv.reader(csvfile, delimiter=',')
12 for row in plots:
---> 13 x.append(int(row[1]))
14 y.append(int(row[2]))
15
ValueError: invalid literal for int() with base 10: 'Open'
from matplotlib import pyplot as plt
import csv
x=[]
y=[]
with open('/Users/thomasmac/Desktop/Orbital/SPLS.csv', 'r') as csvfile:
plots=csv.reader(csvfile, delimiter=',')
for row in plots:
x.append(int(row[0]))
y.append(int(row[1]))
plt.plot(x,y)
plt.title('SPLS')
plt.ylabel('returns')
plt.xlabel('Share price')
plt.show()
答案 0 :(得分:0)
我们无法知道要修复的内容,因为我们没有关于输入文件的完整信息。但是你似乎想要读取带有标题的csv文件。这可以通过numpy.loadtxt
或np.genfromtxt
import matplotlib.pyplot as plt
import numpy as np
x, y = np.genfromtxt("filename.csv", delimiter=",", skip_header=1, unpack=True)
plt.plot(x,y)
plt.title('SPLS')
plt.ylabel('returns')
plt.xlabel('Share price')
plt.show()