質問編集履歴

3

コード修正

2018/06/17 05:47

投稿

shougi
shougi

スコア15

test CHANGED
File without changes
test CHANGED
@@ -12,61 +12,71 @@
12
12
 
13
13
  numbers, squared = read_csv('numbers.csv')
14
14
 
15
- File "E:\デスクトップ\python\CCSSVV.py", line 17, in read_csv
15
+ File "E:\デスクトップ\python\CCSSVV.py", line 17, in csv
16
16
 
17
- numbers.append(int(row[0]))
17
+ nu.append(int(row[0]))
18
18
 
19
- ValueError: invalid literal for int() with base 10: '10,100'
19
+ ValueError: invalid literal for int() with base 10: '5,500'
20
20
 
21
21
  `
22
22
 
23
23
  ```
24
24
 
25
+ import matplotlib.pyplot as plt
26
+
25
27
  import csv
26
-
27
- import matplotlib.pyplot as plt
28
28
 
29
29
 
30
30
 
31
- def scatter_plot(x,y):
31
+ #フォント
32
32
 
33
- plt.scatter(x,y)
33
+ from matplotlib.font_manager import FontProperties
34
34
 
35
- plt.xlabel('Number')
35
+ fp = Fontproperties(fname ='C:\・・・',size = 14)
36
36
 
37
+ #読み込み
38
+
39
+ def csv(d):
40
+
41
+ nu = []
42
+
43
+ sq = []
44
+
45
+ with open(d) as f:
46
+
47
+ r = csv.r(f)
48
+
49
+ next(r)
50
+
51
+ for row in r:
52
+
53
+ nu.append(int(row[0]))
54
+
55
+ sq.append(int(row[1]))
56
+
57
+ return nu, sq
58
+
59
+ #プロット
60
+
61
+ def plot(x,y):
62
+
63
+ plt.plot(x,y)
64
+
37
- plt.ylabel('Square')
65
+ plt.ylabel('番号')
66
+
67
+ plt.xlabel('四角')
38
68
 
39
69
  plt.show()
40
70
 
41
71
 
42
72
 
43
- def read_csv(filename):
44
-
45
- numbers = []
46
-
47
- squared = []
48
-
49
- with open(filename) as f:
50
-
51
- reader = csv.reader(f)
52
-
53
- next(reader)
54
-
55
- for row in reader:
56
-
57
- numbers.append(int(row[0]))
58
-
59
- squared.append(int(row[1]))
60
-
61
- return numbers, squared
62
-
63
73
 
64
74
 
65
75
  if __name__ == '__main__':
66
76
 
67
- numbers, squared = read_csv('numbers.csv')
77
+ nu, sq = csv('ゴキブリ.csv')
68
78
 
69
- scatter_plot(numbers, squared)
79
+ plot(nu, sq)
70
80
 
71
81
 
72
82
 
@@ -76,13 +86,13 @@
76
86
 
77
87
  失礼致しました.CSVファイルをテキストエディタで開いたとき表示されたものです.
78
88
 
79
- "Numbers,Squared"
89
+ "番号,四角"
80
90
 
81
- "10,100"
91
+ "5,500"
82
92
 
83
- "9,81"
93
+ "5,81"
84
94
 
85
- "22,484"
95
+ "19,4"
86
96
 
87
97
 
88
98
 

2

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

2018/06/17 05:47

投稿

shougi
shougi

スコア15

test CHANGED
File without changes
test CHANGED
@@ -80,7 +80,7 @@
80
80
 
81
81
  "10,100"
82
82
 
83
- "981"
83
+ "9,81"
84
84
 
85
85
  "22,484"
86
86
 

1

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

2018/05/30 12:35

投稿

shougi
shougi

スコア15

test CHANGED
File without changes
test CHANGED
@@ -20,7 +20,7 @@
20
20
 
21
21
  `
22
22
 
23
- **
23
+ ```
24
24
 
25
25
  import csv
26
26
 
@@ -68,4 +68,22 @@
68
68
 
69
69
  scatter_plot(numbers, squared)
70
70
 
71
+
72
+
73
+ ```
74
+
71
75
  **
76
+
77
+ 失礼致しました.CSVファイルをテキストエディタで開いたとき表示されたものです.
78
+
79
+ "Numbers,Squared"
80
+
81
+ "10,100"
82
+
83
+ "981"
84
+
85
+ "22,484"
86
+
87
+
88
+
89
+ **