Python 3.x Python 3;MatplotLib;方框图错误

Python 3.x Python 3;MatplotLib;方框图错误,python-3.x,pandas,matplotlib,Python 3.x,Pandas,Matplotlib,我是python/pandas新手,尝试使用iris数据集创建箱线图 这是我的密码 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_widt

我是python/pandas新手,尝试使用iris数据集创建箱线图

这是我的密码

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)
我得到这个错误:

---------------------------------------------------------------------------
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'
---------------------------------------------------------------------------
TypeError回溯(最近一次调用上次)
在()
---->1 plt.箱线图(iris)
/箱线图中的anaconda/lib/python3.5/site-packages/matplotlib/pyplot.py
2784晶须圈=晶须圈,
2785 manage\u xticks=manage\u xticks,autorange=autorange,
->2786 zorder=zorder,data=data)
2787最后:
2788 ax.\U hold=洗旧
/内部的anaconda/lib/python3.5/site packages/matplotlib/__init__.py(ax,*args,**kwargs)
1890警告。警告(消息%(标签名称,函数名称),
1891运行时警告,堆栈级别=2)
->1892返回函数(ax,*args,**kwargs)
1893预存单据=内部单据__
1894如果pre_doc为无:
/箱线图中的anaconda/lib/python3.5/site-packages/matplotlib/axes//u axes.py(self、x、notch、sym、vert、whis、positions、width、patch\u artist、bootstrap、usermedians、conf\u interval、meanline、showmeans、showcaps、showbox、showfliers、boxprops、flips、medianpprops、meanprops、willsprops、manage\xticks、autorange、zorder)
3266 bootstrap=rcParams['boxplot.bootstrap']
3267 bxpstats=cbook.boxplot_stats(x,whis=whis,bootstrap=bootstrap,
->3268标签=标签,自动范围=自动范围)
3269如果槽口为无:
3270槽口=rcParams['boxplot.notch']
/箱线图统计中的anaconda/lib/python3.5/site-packages/matplotlib/cbook.py(X、whis、引导、标签、自动范围)
1984
1985#将X转换为列表列表
->1986年X=_重塑_2D(X)
1987
1988年ncols=len(X)
/anaconda/lib/python3.5/site-packages/matplotlib/cbook.py in_重塑_2D(X)
2245 X=[X.ravel()]
2246其他:
->2247 X=[X[:,i]表示X范围内的i(ncols)]
2248其他:
2249 raise VALUE ERROR(“输入'X'必须有2个或更少的维度”)
/anaconda/lib/python3.5/site-packages/matplotlib/cbook.py in(.0)
2245 X=[X.ravel()]
2246其他:
->2247 X=[X[:,i]表示X范围内的i(ncols)]
2248其他:
2249 raise VALUE ERROR(“输入'X'必须有2个或更少的维度”)
/anaconda/lib/python3.5/site-packages/pandas/core/frame.py in____getitem_u___(self,key)
2057返回自我。\u获取项目\u多级(键)
2058其他:
->2059返回自我。\u获取项目\u列(键)
2060
2061 def_getitem_列(自身,键):
/_getitem_列中的anaconda/lib/python3.5/site-packages/pandas/core/frame.py(self,key)
2064#获取列
2065如果self.columns.u是唯一的:
->2066返回自我。\u获取\u项目\u缓存(密钥)
2067
2068#重复列和可能的降维
/anaconda/lib/python3.5/site-packages/pandas/core/generic.py in_get_item_缓存(self,item)
1382“返回缓存项,项表示标签索引器。”“”
1383缓存=自身。\u项目\u缓存
->1384 res=cache.get(项)
1385如果res为无:
1386 values=self.\u data.get(项目)
TypeError:不可损坏的类型:“切片”

我在网上搜索了这个问题,似乎找不到这个问题的答案。我将非常感谢您在这方面提供的任何帮助。

您正在调用matplotlib来框绘数据帧虹膜。。。由于您已经在使用Pandas导入.csv,您还应该使用它进行打印:

iris.boxplot()