1

Want to plot some data from a pandas dataframe

Relevant info

df13.head()

Country     HDI
1   Norway  0.949
2   Australia   0.939
3   Switzerland     0.939
4   Germany     0.926
5   Denmark     0.925

df13.shape
>>> (169, 2)

df13['HDI'].dtype
>>> dtype('float64')

len(df13['Country'].unique())
>>> 169

So there's no duplicate Country Names

Doing a plot this way creates a plot without the Country names

df13.plot.barh(figsize=(20,20), use_index=False)

enter image description here

Trying to assign the x,y to the plot throws an error, doing it with HDI column only the digits column throws this error

df13.plot(kind='barh', x='HDI')

TypeErrorTraceback (most recent call last)
<ipython-input-77-c7ec3932c7c4> in <module>()
----> 1 df13.plot(kind='barh', x='HDI')

c:\python27\lib\site-packages\pandas\plotting\_core.pyc 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)
   2939                           fontsize=fontsize, colormap=colormap, table=table,
   2940                           yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 2941                           sort_columns=sort_columns, **kwds)
   2942     __call__.__doc__ = plot_frame.__doc__
   2943 

c:\python27\lib\site-packages\pandas\plotting\_core.pyc 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)
   1975                  yerr=yerr, xerr=xerr,
   1976                  secondary_y=secondary_y, sort_columns=sort_columns,
-> 1977                  **kwds)
   1978 
   1979 

c:\python27\lib\site-packages\pandas\plotting\_core.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
   1802         plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
   1803 
-> 1804     plot_obj.generate()
   1805     plot_obj.draw()
   1806     return plot_obj.result

c:\python27\lib\site-packages\pandas\plotting\_core.pyc in generate(self)
    256     def generate(self):
    257         self._args_adjust()
--> 258         self._compute_plot_data()
    259         self._setup_subplots()
    260         self._make_plot()

c:\python27\lib\site-packages\pandas\plotting\_core.pyc in _compute_plot_data(self)
    371         if is_empty:
    372             raise TypeError('Empty {0!r}: no numeric data to '
--> 373                             'plot'.format(numeric_data.__class__.__name__))
    374 
    375         self.data = numeric_data

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

Not sure why this error pops up, I also checked for null values and there's none.

df13.isnull().any()

Country    False
HDI        False
dtype: bool

1 Answer 1

2

You are getting this error because in 'barh' plot bars are horisontal and 'HDI' is on y-axis.

Try this one:

df13.plot(kind='barh', y='HDI')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.