2017-03-25 2 views
1

저는 python/pandas를 처음 사용하고 iris 데이터 세트를 사용하여 boxplot을 만들려고합니다.파이썬 3; MatplotLib; Box Plot Error

--------------------------------------------------------------------------- 
TypeError         Traceback (most recent call last) 
<ipython-input-20-e190e88674b0> in <module>() 
----> 1 plt.boxplot(iris) 

/anaconda/lib/python3.5/site-packages/matplotlib/pyplot.py in boxplot(x, notch, sym, vert, whis, positions, widths, patch_artist, bootstrap, usermedians, conf_intervals, meanline, showmeans, showcaps, showbox, showfliers, boxprops, labels, flierprops, medianprops, meanprops, capprops, whiskerprops, manage_xticks, autorange, zorder, hold, data) 
    2784       whiskerprops=whiskerprops, 
    2785       manage_xticks=manage_xticks, autorange=autorange, 
-> 2786       zorder=zorder, data=data) 
    2787  finally: 
    2788   ax._hold = washold 

/anaconda/lib/python3.5/site-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs) 
    1890      warnings.warn(msg % (label_namer, func.__name__), 
    1891         RuntimeWarning, stacklevel=2) 
-> 1892    return func(ax, *args, **kwargs) 
    1893   pre_doc = inner.__doc__ 
    1894   if pre_doc is None: 

/anaconda/lib/python3.5/site-packages/matplotlib/axes/_axes.py in boxplot(self, x, notch, sym, vert, whis, positions, widths, patch_artist, bootstrap, usermedians, conf_intervals, meanline, showmeans, showcaps, showbox, showfliers, boxprops, labels, flierprops, medianprops, meanprops, capprops, whiskerprops, manage_xticks, autorange, zorder) 
    3266    bootstrap = rcParams['boxplot.bootstrap'] 
    3267   bxpstats = cbook.boxplot_stats(x, whis=whis, bootstrap=bootstrap, 
-> 3268          labels=labels, autorange=autorange) 
    3269   if notch is None: 
    3270    notch = rcParams['boxplot.notch'] 

/anaconda/lib/python3.5/site-packages/matplotlib/cbook.py in boxplot_stats(X, whis, bootstrap, labels, autorange) 
    1984 
    1985  # convert X to a list of lists 
-> 1986  X = _reshape_2D(X) 
    1987 
    1988  ncols = len(X) 

/anaconda/lib/python3.5/site-packages/matplotlib/cbook.py in _reshape_2D(X) 
    2245     X = [X.ravel()] 
    2246    else: 
-> 2247     X = [X[:, i] for i in xrange(ncols)] 
    2248   else: 
    2249    raise ValueError("input `X` must have 2 or fewer dimensions") 

/anaconda/lib/python3.5/site-packages/matplotlib/cbook.py in <listcomp>(.0) 
    2245     X = [X.ravel()] 
    2246    else: 
-> 2247     X = [X[:, i] for i in xrange(ncols)] 
    2248   else: 
    2249    raise ValueError("input `X` must have 2 or fewer dimensions") 

/anaconda/lib/python3.5/site-packages/pandas/core/frame.py in __getitem__(self, key) 
    2057    return self._getitem_multilevel(key) 
    2058   else: 
-> 2059    return self._getitem_column(key) 
    2060 
    2061  def _getitem_column(self, key): 

/anaconda/lib/python3.5/site-packages/pandas/core/frame.py in _getitem_column(self, key) 
    2064   # get column 
    2065   if self.columns.is_unique: 
-> 2066    return self._get_item_cache(key) 
    2067 
    2068   # duplicate columns & possible reduce dimensionality 

/anaconda/lib/python3.5/site-packages/pandas/core/generic.py in _get_item_cache(self, item) 
    1382   """Return the cached item, item represents a label indexer.""" 
    1383   cache = self._item_cache 
-> 1384   res = cache.get(item) 
    1385   if res is None: 
    1386    values = self._data.get(item) 

TypeError: unhashable type: 'slice' 

내가 haae이의 웹을 검색하고이 문제에 대한 답을 찾을 수 없습니다 :

는 여기에이 오류가 내 코드 :

import pandas as pd 
iris_filename = '/Users/pro/Documents/Code/Data Science/Iris/IRIS.csv' 
    iris = pd.read_csv(iris_filename, header = None, 
names= ['sepal_lenght','sepal_width','petal_lenght','petal_width','target']) 
plt.boxplot(iris) 

입니다. 이것에 대한 도움을 주시면 감사하겠습니다.

답변

1

원하는 작업 ... DataFrame 조리개를 상자 그림을하기 matplotlib를 호출 이미 .CSV를 가져 오기위한 팬더을 사용하는 당신은 또한 플롯을 위해 사용한다 :

iris.boxplot() 

Pandas boxplot api