我有一个pandas DataFrame。列,头部和dtypes如下所示:
print sorted_results.dtypes
print sorted_results[['coefficients']].head()
0 object
coefficients float64
dtype: object
coefficients
62 2.432853
70 2.187059
19 1.804636
68 1.507075
130 1.120488
我想使用matplot lib绘制条形图,所以
plt.barh(range(len(sorted_results)), sorted_results[['coefficients']])
给出以下内容:
ValueError Traceback (most recent call last)
<ipython-input-17-1d344a50d686> in <module>()
1
----> 2 plt.barh(range(len(sorted_results)), sorted_results[['coefficients']])
/Users/sram/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.pyc in barh(bottom, width, height, left, hold, **kwargs)
2665 ax.hold(hold)
2666 try:
-> 2667 ret = ax.barh(bottom, width, height=height, left=left, **kwargs)
2668 finally:
2669 ax.hold(washold)
/Users/sram/anaconda/lib/python2.7/site-packages/matplotlib/axes/_axes.pyc in barh(self, bottom, width, height, left, **kwargs)
2245
2246 patches = self.bar(left=left, height=height, width=width,
-> 2247 bottom=bottom, orientation='horizontal', **kwargs)
2248 return patches
2249
/Users/sram/anaconda/lib/python2.7/site-packages/matplotlib/__init__.pyc in inner(ax, *args, **kwargs)
1817 warnings.warn(msg % (label_namer, func.__name__),
1818 RuntimeWarning, stacklevel=2)
-> 1819 return func(ax, *args, **kwargs)
1820 pre_doc = inner.__doc__
1821 if pre_doc is None:
/Users/sram/anaconda/lib/python2.7/site-packages/matplotlib/axes/_axes.pyc in bar(self, left, height, width, bottom, **kwargs)
2085 edgecolor=e,
2086 linewidth=lw,
-> 2087 label='_nolegend_'
2088 )
2089 r.update(kwargs)
/Users/sram/anaconda/lib/python2.7/site-packages/matplotlib/patches.pyc in __init__(self, xy, width, height, angle, **kwargs)
640 self._x = float(xy[0])
641 self._y = float(xy[1])
--> 642 self._width = float(width)
643 self._height = float(height)
644 self._angle = float(angle)
ValueError: could not convert string to float: coefficients
系数似乎具有正确的数据类型。我为什么在这里做错了我感到难过