テキストファイルをインポートした後に基本的なグラフを出力する簡単なプログラムを書いています。次のエラーが表示されます。
Traceback (most recent call last):
File "C:\Users\Chris1\Desktop\attempt2\ex1.py", line 13, in <module>
x.append(int(xAndY[0]))
ValueError: invalid literal for int() with base 10: '270.286'
私のpythonコードは次のようになります:
import matplotlib.pyplot as plt
x = []
y = []
readFile = open ('temp.txt', 'r')
sepFile = readFile.read().split('\n')
readFile.close()
for plotPair in sepFile:
xAndY = plotPair.split(',')
x.append(int(xAndY[0]))
y.append(int(xAndY[1]))
print x
print y
plt.plot(x, y)
plt.title('example 1')
plt.xlabel('D')
plt.ylabel('Frequency')
plt.show()
テキスト ファイルのスニペットは次のようになります。
270.286,4.353,16968.982,1903.115
38.934,68.608,16909.727,1930.394
190.989,1.148,16785.367,1969.925
問題は軽微ですが、自分で解決できないようです ありがとう