使用Pandas Dataframe绘制条形图

时间:2018-12-20 17:43:42

标签: python pandas plot

我有一个包含2列的数据框:一个是运动的名称,另一个是每个运动中的运动员人数。我尝试使用以下方法绘制条形图:

ax = div1[['Sport','Athletes']].plot(kind='bar', title="abcd", figsize=(15, 10), legend=True, fontsize=12)

[用于绘制条形图的数据] [1]

但是我遇到了以下错误:


TypeError                                 Traceback (most recent call last)
<ipython-input-36-29052602d3cd> in <module>()
----> 1 ax = div1[['Sport','Athletes']].plot(kind='bar', title="abcd", figsize=(15, 10), legend=True, fontsize=12)

/opt/conda/lib/python3.5/site-packages/pandas/tools/plotting.py in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
   3772                           fontsize=fontsize, colormap=colormap, table=table,
   3773                           yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 3774                           sort_columns=sort_columns, **kwds)
   3775     __call__.__doc__ = plot_frame.__doc__
   3776 

/opt/conda/lib/python3.5/site-packages/pandas/tools/plotting.py in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
   2641                  yerr=yerr, xerr=xerr,
   2642                  secondary_y=secondary_y, sort_columns=sort_columns,
-> 2643                  **kwds)
   2644 
   2645 

/opt/conda/lib/python3.5/site-packages/pandas/tools/plotting.py in _plot(data, x, y, subplots, ax, kind, **kwds)
   2468         plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
   2469 
-> 2470     plot_obj.generate()
   2471     plot_obj.draw()
   2472     return plot_obj.result

/opt/conda/lib/python3.5/site-packages/pandas/tools/plotting.py in generate(self)
   1039     def generate(self):
   1040         self._args_adjust()
-> 1041         self._compute_plot_data()
   1042         self._setup_subplots()
   1043         self._make_plot()

/opt/conda/lib/python3.5/site-packages/pandas/tools/plotting.py in _compute_plot_data(self)
   1148         if is_empty:
   1149             raise TypeError('Empty {0!r}: no numeric data to '
-> 1150                             'plot'.format(numeric_data.__class__.__name__))
   1151 
   1152         self.data = numeric_data

TypeError: Empty 'DataFrame': no numeric data to plot

有人可以告诉我我要去哪里错吗?提前致谢。       [1]:https://i.stack.imgur.com/yeIXz.png

0 个答案:

没有答案