質問するログイン新規登録

質問編集履歴

3

コード修正

2018/06/17 05:47

投稿

shougi
shougi

スコア15

title CHANGED
File without changes
body CHANGED
@@ -5,41 +5,46 @@
5
5
  Traceback (most recent call last):
6
6
  File "E:\デスクトップ\python\CCSSVV.py", line 22, in <module>
7
7
  numbers, squared = read_csv('numbers.csv')
8
- File "E:\デスクトップ\python\CCSSVV.py", line 17, in read_csv
8
+ File "E:\デスクトップ\python\CCSSVV.py", line 17, in csv
9
- numbers.append(int(row[0]))
9
+ nu.append(int(row[0]))
10
- ValueError: invalid literal for int() with base 10: '10,100'
10
+ ValueError: invalid literal for int() with base 10: '5,500'
11
11
  `
12
12
  ```
13
+ import matplotlib.pyplot as plt
13
14
  import csv
14
- import matplotlib.pyplot as plt
15
15
 
16
+ #フォント
17
+ from matplotlib.font_manager import FontProperties
18
+ fp = Fontproperties(fname ='C:\・・・',size = 14)
19
+ #読み込み
20
+ def csv(d):
21
+ nu = []
22
+ sq = []
23
+ with open(d) as f:
24
+ r = csv.r(f)
25
+ next(r)
26
+ for row in r:
27
+ nu.append(int(row[0]))
28
+ sq.append(int(row[1]))
29
+ return nu, sq
30
+ #プロット
16
- def scatter_plot(x,y):
31
+ def plot(x,y):
17
- plt.scatter(x,y)
32
+ plt.plot(x,y)
33
+ plt.ylabel('番号')
18
- plt.xlabel('Number')
34
+ plt.xlabel('四角')
19
- plt.ylabel('Square')
20
35
  plt.show()
21
36
 
22
- def read_csv(filename):
23
- numbers = []
24
- squared = []
25
- with open(filename) as f:
26
- reader = csv.reader(f)
27
- next(reader)
28
- for row in reader:
29
- numbers.append(int(row[0]))
30
- squared.append(int(row[1]))
31
- return numbers, squared
32
37
 
33
38
  if __name__ == '__main__':
34
- numbers, squared = read_csv('numbers.csv')
39
+ nu, sq = csv('ゴキブリ.csv')
35
- scatter_plot(numbers, squared)
40
+ plot(nu, sq)
36
41
 
37
42
  ```
38
43
  **
39
44
  失礼致しました.CSVファイルをテキストエディタで開いたとき表示されたものです.
40
- "Numbers,Squared"
45
+ "番号,四角"
41
- "10,100"
46
+ "5,500"
42
- "9,81"
47
+ "5,81"
43
- "22,484"
48
+ "19,4"
44
49
 
45
50
  **

2

コピー内容を正確に入力した

2018/06/17 05:47

投稿

shougi
shougi

スコア15

title CHANGED
File without changes
body CHANGED
@@ -39,7 +39,7 @@
39
39
  失礼致しました.CSVファイルをテキストエディタで開いたとき表示されたものです.
40
40
  "Numbers,Squared"
41
41
  "10,100"
42
- "981"
42
+ "9,81"
43
43
  "22,484"
44
44
 
45
45
  **

1

CSVファイルの中身テキストエディタから打ち出しました.

2018/05/30 12:35

投稿

shougi
shougi

スコア15

title CHANGED
File without changes
body CHANGED
@@ -9,7 +9,7 @@
9
9
  numbers.append(int(row[0]))
10
10
  ValueError: invalid literal for int() with base 10: '10,100'
11
11
  `
12
- **
12
+ ```
13
13
  import csv
14
14
  import matplotlib.pyplot as plt
15
15
 
@@ -33,4 +33,13 @@
33
33
  if __name__ == '__main__':
34
34
  numbers, squared = read_csv('numbers.csv')
35
35
  scatter_plot(numbers, squared)
36
+
37
+ ```
38
+ **
39
+ 失礼致しました.CSVファイルをテキストエディタで開いたとき表示されたものです.
40
+ "Numbers,Squared"
41
+ "10,100"
42
+ "981"
43
+ "22,484"
44
+
36
45
  **