前提・実現したいこと
csvファイルから必要なデータを抜き出してグラフ化したいです。
ここに質問の内容を詳しく書いてください。
発生している問題・エラーメッセージ
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
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
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
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
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
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
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
このcsvファイルからseasonとPTSのデータの関係性をグラフ化しようと思いました。
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import os
df = pd.read_csv('LebronJames.csv', names=['Season', 'PTS'])
print(df.describe())
plt.plot(range(0,6),df['PTS'],marker="o")
plt.title('PTSchart')
plt.xlabel('Season')
plt.ylabel('PTS')
plt.show()
エラーメッセージ
Season PTS
count 7 7
unique 6 6
top 1.6 25.3
freq 2 2
ValueError Traceback (most recent call last)
<ipython-input-53-2adacddf01cf> in <module>()
1 df = pd.read_csv('LebronJames.csv', names=['Season', 'PTS'])
2 print(df.describe())
----> 3 plt.plot(range(0,6),df['PTS'],marker="o")
4 plt.title('PTSchart')
5 plt.xlabel('Season')
/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py in plot(*args, **kwargs)
3259 mplDeprecation)
3260 try:
-> 3261 ret = ax.plot(*args, **kwargs)
3262 finally:
3263 ax._hold = washold
/anaconda3/lib/python3.6/site-packages/matplotlib/init.py in inner(ax, *args, **kwargs)
1715 warnings.warn(msg % (label_namer, func.name),
1716 RuntimeWarning, stacklevel=2)
-> 1717 return func(ax, *args, **kwargs)
1718 pre_doc = inner.doc
1719 if pre_doc is None:
/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_axes.py in plot(self, *args, **kwargs)
1370 kwargs = cbook.normalize_kwargs(kwargs, _alias_map)
1371
-> 1372 for line in self._get_lines(*args, **kwargs):
1373 self.add_line(line)
1374 lines.append(line)
/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_base.py in _grab_next_args(self, *args, **kwargs)
402 this += args[0],
403 args = args[1:]
--> 404 for seg in self._plot_args(this, kwargs):
405 yield seg
406
/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_base.py in _plot_args(self, tup, kwargs)
382 x, y = index_of(tup[-1])
383
--> 384 x, y = self._xy_from_xy(x, y)
385
386 if self.command == 'plot':
/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_base.py in _xy_from_xy(self, x, y)
241 if x.shape[0] != y.shape[0]:
242 raise ValueError("x and y must have same first dimension, but "
--> 243 "have shapes {} and {}".format(x.shape, y.shape))
244 if x.ndim > 2 or y.ndim > 2:
245 raise ValueError("x and y can be no greater than 2-D, but have "
ValueError: x and y must have same first dimension, but have shapes (6,) and (7,)
In [ ]:
回答1件
あなたの回答
tips
プレビュー