質問編集履歴

1

質問内容を細分化しました。

2018/06/07 01:12

投稿

24pokopoko
24pokopoko

スコア7

test CHANGED
@@ -1 +1 @@
1
- Pythonで数値予測
1
+ csvファイルからグラフを書く
test CHANGED
@@ -1,5 +1,169 @@
1
- csvファイルを使ってsklearnで数値予測する方法がわかりません。
1
+ ### 前提・実現したいこと
2
2
 
3
- NBA選手の過去のデータから次の一年の成績数値で予測したいです。
3
+ csvファイルから必要なデータを抜き出てグラフ化したいです。
4
4
 
5
- どういったコード使うのかも全わかりません。教えてください
5
+ ここに質問の内容詳し書いてください
6
+
7
+
8
+
9
+ ### 発生している問題・エラーメッセージ
10
+
11
+ Season,Age,Tm,Lg,Pos,G,GS,MP,FG,FGA,FG%,3P,3PA,3P%,2P,2PA,2P%,eFG%,FT,FTA,FT%,ORB,DRB,TRB,AST,STL,BLK,TOV,PF,PTS
12
+
13
+ 2012-13,28,MIA,NBA,PF,76,76,37.9,10.1,17.8,0.565,1.4,3.3,0.406,8.7,14.5,0.602,0.603,5.3,7,0.753,1.3,6.8,8,7.3,1.7,0.9,3,1.4,26.8
14
+
15
+ 2013-14,29,MIA,NBA,PF,77,77,37.7,10,17.6,0.567,1.5,4,0.379,8.5,13.6,0.622,0.61,5.7,7.6,0.75,1.1,5.9,6.9,6.3,1.6,0.3,3.5,1.6,27.1
16
+
17
+ 2014-15,30,CLE,NBA,SF,69,69,36.1,9,18.5,0.488,1.7,4.9,0.354,7.3,13.6,0.536,0.535,5.4,7.7,0.71,0.7,5.3,6,7.4,1.6,0.7,3.9,2,25.3
18
+
19
+ 2015-16,31,CLE,NBA,SF,76,76,35.6,9.7,18.6,0.52,1.1,3.7,0.309,8.6,14.9,0.573,0.551,4.7,6.5,0.731,1.5,6,7.4,6.8,1.4,0.6,3.3,1.9,25.3
20
+
21
+ 2016-17,32,CLE,NBA,SF,74,74,37.8,9.9,18.2,0.548,1.7,4.6,0.363,8.3,13.5,0.611,0.594,4.8,7.2,0.674,1.3,7.3,8.6,8.7,1.2,0.6,4.1,1.8,26.4
22
+
23
+ 2017-18,33,CLE,NBA,PF,82,82,36.9,10.5,19.3,0.542,1.8,5,0.367,8.6,14.3,0.603,0.59,4.7,6.5,0.731,1.2,7.5,8.6,9.1,1.4,0.9,4.2,1.6,27.5
24
+
25
+ このcsvファイルからseasonとPTSのデータの関係性をグラフ化しようと思いました。
26
+
27
+ import numpy as np
28
+
29
+ import matplotlib.pyplot as plt
30
+
31
+ import pandas as pd
32
+
33
+ import os
34
+
35
+ df = pd.read_csv('LebronJames.csv', names=['Season', 'PTS'])
36
+
37
+ print(df.describe())
38
+
39
+ plt.plot(range(0,6),df['PTS'],marker="o")
40
+
41
+ plt.title('PTSchart')
42
+
43
+ plt.xlabel('Season')
44
+
45
+ plt.ylabel('PTS')
46
+
47
+ plt.show()
48
+
49
+ エラーメッセージ
50
+
51
+ Season PTS
52
+
53
+ count 7 7
54
+
55
+ unique 6 6
56
+
57
+ top 1.6 25.3
58
+
59
+ freq 2 2
60
+
61
+ ---------------------------------------------------------------------------
62
+
63
+ ValueError Traceback (most recent call last)
64
+
65
+ <ipython-input-53-2adacddf01cf> in <module>()
66
+
67
+ 1 df = pd.read_csv('LebronJames.csv', names=['Season', 'PTS'])
68
+
69
+ 2 print(df.describe())
70
+
71
+ ----> 3 plt.plot(range(0,6),df['PTS'],marker="o")
72
+
73
+ 4 plt.title('PTSchart')
74
+
75
+ 5 plt.xlabel('Season')
76
+
77
+
78
+
79
+ /anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py in plot(*args, **kwargs)
80
+
81
+ 3259 mplDeprecation)
82
+
83
+ 3260 try:
84
+
85
+ -> 3261 ret = ax.plot(*args, **kwargs)
86
+
87
+ 3262 finally:
88
+
89
+ 3263 ax._hold = washold
90
+
91
+
92
+
93
+ /anaconda3/lib/python3.6/site-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs)
94
+
95
+ 1715 warnings.warn(msg % (label_namer, func.__name__),
96
+
97
+ 1716 RuntimeWarning, stacklevel=2)
98
+
99
+ -> 1717 return func(ax, *args, **kwargs)
100
+
101
+ 1718 pre_doc = inner.__doc__
102
+
103
+ 1719 if pre_doc is None:
104
+
105
+
106
+
107
+ /anaconda3/lib/python3.6/site-packages/matplotlib/axes/_axes.py in plot(self, *args, **kwargs)
108
+
109
+ 1370 kwargs = cbook.normalize_kwargs(kwargs, _alias_map)
110
+
111
+ 1371
112
+
113
+ -> 1372 for line in self._get_lines(*args, **kwargs):
114
+
115
+ 1373 self.add_line(line)
116
+
117
+ 1374 lines.append(line)
118
+
119
+
120
+
121
+ /anaconda3/lib/python3.6/site-packages/matplotlib/axes/_base.py in _grab_next_args(self, *args, **kwargs)
122
+
123
+ 402 this += args[0],
124
+
125
+ 403 args = args[1:]
126
+
127
+ --> 404 for seg in self._plot_args(this, kwargs):
128
+
129
+ 405 yield seg
130
+
131
+ 406
132
+
133
+
134
+
135
+ /anaconda3/lib/python3.6/site-packages/matplotlib/axes/_base.py in _plot_args(self, tup, kwargs)
136
+
137
+ 382 x, y = index_of(tup[-1])
138
+
139
+ 383
140
+
141
+ --> 384 x, y = self._xy_from_xy(x, y)
142
+
143
+ 385
144
+
145
+ 386 if self.command == 'plot':
146
+
147
+
148
+
149
+ /anaconda3/lib/python3.6/site-packages/matplotlib/axes/_base.py in _xy_from_xy(self, x, y)
150
+
151
+ 241 if x.shape[0] != y.shape[0]:
152
+
153
+ 242 raise ValueError("x and y must have same first dimension, but "
154
+
155
+ --> 243 "have shapes {} and {}".format(x.shape, y.shape))
156
+
157
+ 244 if x.ndim > 2 or y.ndim > 2:
158
+
159
+ 245 raise ValueError("x and y can be no greater than 2-D, but have "
160
+
161
+
162
+
163
+ ValueError: x and y must have same first dimension, but have shapes (6,) and (7,)
164
+
165
+
166
+
167
+
168
+
169
+ In [ ]: