scl*_*ee1 1 python matplotlib pandas
我正在使用Python3,当我一直在研究它时,我遇到了问题.我编码如下,我找到了我预期的正确结果.然后我希望将结果看作图表.所以我试图绘制它,但我收到意外错误,表明我需要matplotlib.因为我在第一个代码中导入了matplotlib,所以我不知道解决这个问题.
import matplotlib.pyplot as plt
%matplotlib inline
train.Survived[train['Name']=='Mr'].value_counts()
#Result
0 436
1 81
Name: Survived, dtype: int64
Run Code Online (Sandbox Code Playgroud)
我输入以下代码,将它们视为饼图.
train.Survived[train['Name']=='Mr'].value_counts().plot(kind='pie')
Run Code Online (Sandbox Code Playgroud)
错误消息如下.
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-191-7f60a15206ad> in <module>()
1 import pandas.plotting
----> 2 train.Survived[train['Name']=='Mr'].value_counts().plot(kind='pie')
/usr/local/lib/python3.6/site-packages/pandas/plotting/_core.py in __call__(self, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
2739 colormap=colormap, table=table, yerr=yerr,
2740 xerr=xerr, label=label, secondary_y=secondary_y,
-> 2741 **kwds)
2742 __call__.__doc__ = plot_series.__doc__
2743
/usr/local/lib/python3.6/site-packages/pandas/plotting/_core.py in plot_series(data, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
2000 yerr=yerr, xerr=xerr,
2001 label=label, secondary_y=secondary_y,
-> 2002 **kwds)
2003
2004
/usr/local/lib/python3.6/site-packages/pandas/plotting/_core.py in _plot(data, x, y, subplots, ax, kind, **kwds)
1757 data = data[y].copy()
1758 data.index.name = y
-> 1759 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
1760 else:
1761 if isinstance(data, ABCDataFrame):
/usr/local/lib/python3.6/site-packages/pandas/plotting/_core.py in __init__(self, data, kind, **kwargs)
1498 if (data < 0).any().any():
1499 raise ValueError("{0} doesn't allow negative values".format(kind))
-> 1500 MPLPlot.__init__(self, data, kind=kind, **kwargs)
1501
1502 def _args_adjust(self):
/usr/local/lib/python3.6/site-packages/pandas/plotting/_core.py in __init__(self, data, kind, by, subplots, sharex, sharey, use_index, figsize, grid, legend, rot, ax, fig, title, xlim, ylim, xticks, yticks, sort_columns, fontsize, secondary_y, colormap, table, layout, **kwds)
105 table=False, layout=None, **kwds):
106
--> 107 _raise_if_no_mpl()
108 _converter._WARN = False
109 self.data = data
/usr/local/lib/python3.6/site-packages/pandas/plotting/_core.py in _raise_if_no_mpl()
55 # TODO(mpl_converter): remove once converter is explicit
56 if not _HAS_MPL:
---> 57 raise ImportError("matplotlib is required for plotting.")
58
59
ImportError: matplotlib is required for plotting.
Run Code Online (Sandbox Code Playgroud)
如果你能解决我的问题,我真的很感激.谢谢.
| 归档时间: |
|
| 查看次数: |
860 次 |
| 最近记录: |