绘制熊猫数据框

时间:2021-02-25 23:57:04

标签: python pandas dataframe numpy matplotlib

嗨,我最近在正常工作的代码上遇到了错误。无法将 'numpy.generic' 对象的 '<属性 'dtype' 解释为数据类型。因此,我阅读了有关此错误的在线评论并进行了 conda 更新 Pandas,因为人们认为 numy 版本 1.20.1 可能存在不兼容问题。现在我收到一个新错误,因为在选择默认后端“matplotlib”时绘图需要 matplotlib。我怎样才能让情节发挥作用。 这是一个来自熊猫数据框的简单绘图程序

df1 = pd.DataFrame({'word':wordlist, 'count':countlist})
ax=df1.plot.bar(color='g')
ax.set_xlabel(" word")
ax.set_ylabel("Count") 
pl.suptitle("Year 2012")
ImportError                               Traceback (most recent call last)
<ipython-input-22-81ba99f051c4> in <module>
     56 #seri=seri.sort_values('countlist')
     57 
---> 58 ax=df1.plot.bar(color='g')
     59 ax.set_xlabel("Technology word")
     60 ax.set_ylabel("Count")

~\Anaconda3\lib\site-packages\pandas\plotting\_core.py in bar(self, x, y, **kwargs)
   1001            >>> axes = df.plot.line(
   1002            ...     subplots=True, color={"pig": "pink", "horse": "#742802"}
-> 1003            ... )
   1004 
   1005         .. plot::

~\Anaconda3\lib\site-packages\pandas\plotting\_core.py in __call__(self, *args, **kwargs)
    765     _dataframe_kinds = ("scatter", "hexbin")
    766     _kind_aliases = {"density": "kde"}
--> 767     _all_kinds = _common_kinds + _series_kinds + _dataframe_kinds
    768 
    769     def __init__(self, data):

~\Anaconda3\lib\site-packages\pandas\plotting\_core.py in _get_plot_backend(backend)
   1667             the matplotlib function that is used under the hood.
   1668 
-> 1669         Examples
   1670         --------
   1671         The following examples are generated with random data from

ImportError: matplotlib is required for plotting when the default backend "matplotlib" is selected.

0 个答案:

没有答案