python - KeyError: u'no item named 0' comes up with histogram -


i've seen similar questions on here, none seem having exact same problem me. i'm trying create histogram of chemical data. error in other instances seemed related missing column, data doesn't (and shouldn't) have column named "0". here code , error message:

%pylab inline import matplotlib.pyplot plt import pandas pd plt.figure()  #importing data genesis = pd.read_csv(r'c:\connors temp\...... (878-15g)\task_4 (genesis)\genesis_mwmp.csv')  arsenic = genesis[['code','arsenic']] antimony = genesis[['code','antimony']] plt.hist(antimony)   keyerror                                  traceback (most recent call last) <ipython-input-7-c537deba42d9> in <module>() ----> 1 plt.hist(antimony)  c:\python27\lib\site-packages\matplotlib\pyplot.pyc in hist(x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, hold, **kwargs)    2655                       histtype=histtype, align=align, orientation=orientation,    2656                       rwidth=rwidth, log=log, color=color, label=label, -> 2657                       stacked=stacked, **kwargs)    2658         draw_if_interactive()    2659     finally:  c:\python27\lib\site-packages\matplotlib\axes.pyc in hist(self, x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, **kwargs)    8010         # massage 'x' processing.    8011         # note: sure changes here done below 'weights' -> 8012         if isinstance(x, np.ndarray) or not iterable(x[0]):    8013             # todo: support masked arrays;    8014             x = np.asarray(x)  c:\python27\lib\site-packages\pandas\core\frame.pyc in __getitem__(self, key)    1805                 raise valueerror('cannot index using non-boolean dataframe')    1806         else: -> 1807             return self._get_item_cache(key)    1808     1809     def _getitem_array(self, key):  c:\python27\lib\site-packages\pandas\core\generic.pyc in _get_item_cache(self, item)     529             return cache[item]     530         except exception: --> 531             values = self._data.get(item)     532             res = self._box_item_values(item, values)     533             cache[item] = res  c:\python27\lib\site-packages\pandas\core\internals.pyc in get(self, item)     828      829     def get(self, item): --> 830         _, block = self._find_block(item)     831         return block.get(item)     832   c:\python27\lib\site-packages\pandas\core\internals.pyc in _find_block(self, item)     942      943     def _find_block(self, item): --> 944         self._check_have(item)     945         i, block in enumerate(self.blocks):     946             if item in block:      c:\python27\lib\site-packages\pandas\core\internals.pyc in _check_have(self,    item)     949     def _check_have(self, item):     950         if item not in self.items: --> 951             raise keyerror('no item named %s' % com.pprint_thing(item))     952      953     def reindex_axis(self, new_axis, method=none, axis=0, copy=true):  keyerror: u'no item named 0' 

if you're using lower-level libraries (that is, not pandas's wrappers them), should use

hist(antimony.antimony.values) 

(see thehist documentation more).


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -