Pandas plotting with yerr gives key error :0
<p>I am trying to build a plot from a pandas dataframe, but when I pass a slice of this dataframe as yerr, I get a Key error :0.
I have checked and there was a similar issues reported on <a href="https://github.com/pydata/pandas/issues/4493" rel="nofollow noreferrer">pandas page</a> but it is supposed to be resolved so I am not sure where it comes from.
Anybody has an idea on why, or how could I plot those two dataframe?
EDIT :Here is the why <a href="https://github.com/pydata/pandas/issues/11858" rel="nofollow noreferrer">https://github.com/pydata/pandas/issues/11858</a>, anyway way I could work around that problem?</p>

<p>Here is <code>means.plot(kind='bar')</code> now I need yerr :
<a href="https://i.stack.imgur.com/WiCVf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WiCVf.png" alt="That is means.plot(kind=&#39;bar&#39;) now I need yerr"></a></p>

<p>My sliced dataframes looks like that :</p>

<pre><code>#means
condition  scenario_1  scenario_2  scenario_3
date                                         
1950         7857.495    4418.180    4418.180
1960         1361.255     769.095     769.095
1970          947.855     649.875     649.875
1980          743.565     542.350     542.350
1990         4157.495    3780.185    3780.185
2000         4473.730    5953.955    5940.020
2010          962.565     736.735     486.140
2020          663.065     464.065     358.580
2030          609.285     375.195     264.415
2040         1706.620    1167.375    1051.090
2050          882.075     518.810     393.240
2060         1483.740     863.260     778.115
2070         2540.660    2417.420    2392.325
2080         3329.965    2484.215    2332.140
2090         1981.605    1326.115    1363.695

#errors
       scenario_1   scneario_2   scenario_3
date                                       
1950  6882.473594  3977.169284  3977.169284
1960  2063.900035  1209.355869  1209.355869
1970  1641.563211  1132.895230  1132.895230
1980  1304.848179   893.150490   893.150490
1990  4833.384691  4071.813927  4071.813927
2000  3071.053838  3300.206511  3262.672983
2010  1519.563511  1099.878070   703.131441
2020  1085.763048   694.784212   456.909226
2030  1012.836592   647.889589   342.873572
2040  2242.979678  1573.683502  1298.028517
2050  1462.245123   891.855864   517.363621
2060  2225.214719  1213.065737   975.519051
2070  2927.880585  2423.424810  2076.170121
2080  3572.416062  2436.318656  2316.993311
2090  2510.864263  1487.605484  1499.623779

#which I try to plot that way:
means.plot(kind='bar',yerr=errors)
</code></pre>

<p>I can plot the means without problem but then everytime I try to add the yerr it gives me :</p>

<pre><code>KeyError                                  Traceback (most recent call last)
&lt;ipython-input-68-2e629f7a18f3&gt; in &lt;module&gt;()
----&gt; 1 means.plot(kind='bar', yerr=errors)

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/tools/plotting.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)
   3669                           fontsize=fontsize, colormap=colormap, table=table,
   3670                           yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-&gt; 3671                           sort_columns=sort_columns, **kwds)
   3672     __call__.__doc__ = plot_frame.__doc__
   3673 

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/tools/plotting.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)
   2554                  yerr=yerr, xerr=xerr,
   2555                  secondary_y=secondary_y, sort_columns=sort_columns,
-&gt; 2556                  **kwds)
   2557 
   2558 

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
   2382         plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
   2383 
-&gt; 2384     plot_obj.generate()
   2385     plot_obj.draw()
   2386     return plot_obj.result

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/tools/plotting.pyc in generate(self)
    985         self._compute_plot_data()
    986         self._setup_subplots()
--&gt; 987         self._make_plot()
    988         self._add_table()
    989         self._make_legend()

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/tools/plotting.pyc in _make_plot(self)
   1920                 w = self.bar_width / K
   1921                 rect = self._plot(ax, self.ax_pos + (i + 0.5) * w, y, w,
-&gt; 1922                                   start=start, label=label, log=self.log, **kwds)
   1923             self._add_legend_handle(rect, label, index=i)
   1924 

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/tools/plotting.pyc in _plot(cls, ax, x, y, w, start, log, **kwds)
   1870     @classmethod
   1871     def _plot(cls, ax, x, y, w, start=0, log=False, **kwds):
-&gt; 1872         return ax.bar(x, y, w, bottom=start, log=log, **kwds)
   1873 
   1874     @property

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/__init__.pyc in inner(ax, *args, **kwargs)
   1810                     warnings.warn(msg % (label_namer, func.__name__),
   1811                                   RuntimeWarning, stacklevel=2)
-&gt; 1812             return func(ax, *args, **kwargs)
   1813         pre_doc = inner.__doc__
   1814         if pre_doc is None:

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axes/_axes.pyc in bar(self, left, height, width, bottom, **kwargs)
   2154             errorbar = self.errorbar(x, y,
   2155                                      yerr=yerr, xerr=xerr,
-&gt; 2156                                      fmt='none', **error_kw)
   2157         else:
   2158             errorbar = None

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/__init__.pyc in inner(ax, *args, **kwargs)
   1810                     warnings.warn(msg % (label_namer, func.__name__),
   1811                                   RuntimeWarning, stacklevel=2)
-&gt; 1812             return func(ax, *args, **kwargs)
   1813         pre_doc = inner.__doc__
   1814         if pre_doc is None:

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axes/_axes.pyc in errorbar(self, x, y, yerr, xerr, fmt, ecolor, elinewidth, capsize, barsabove, lolims, uplims, xlolims, xuplims, errorevery, capthick, **kwargs)
   2961                 # Check for scalar or symmetric, as in xerr.
   2962                 if len(yerr) &gt; 1 and not ((len(yerr) == len(y) and not (
-&gt; 2963                         iterable(yerr[0]) and len(yerr[0]) &gt; 1))):
   2964                     raise ValueError("yerr must be a scalar, the same "
   2965                                      "dimensions as y, or 2xN.")

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/series.pyc in __getitem__(self, key)
    555     def __getitem__(self, key):
    556         try:
--&gt; 557             result = self.index.get_value(self, key)
    558 
    559             if not np.isscalar(result):

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/index.pyc in get_value(self, series, key)
   1788 
   1789         try:
-&gt; 1790             return self._engine.get_value(s, k)
   1791         except KeyError as e1:
   1792             if len(self) &gt; 0 and self.inferred_type in ['integer','boolean']:

pandas/index.pyx in pandas.index.IndexEngine.get_value (pandas/index.c:3204)()

pandas/index.pyx in pandas.index.IndexEngine.get_value (pandas/index.c:2903)()

pandas/index.pyx in pandas.index.IndexEngine.get_loc (pandas/index.c:3843)()

pandas/hashtable.pyx in pandas.hashtable.Int64HashTable.get_item (pandas/hashtable.c:6525)()

pandas/hashtable.pyx in pandas.hashtable.Int64HashTable.get_item (pandas/hashtable.c:6463)()

KeyError: 0
</code></pre>

<p>I read that the index for the yerr had to contain 0, so I tried that as well but I get the same error. Frustratingly enough though if I just plot means of scenario_1 with errors of scneario_1 it works...</p>

<p>I just upgraded both pandas and matplotlib.</p>

<p>Here is the ugly code used to get the dataframe ready :</p>

<pre><code>frames = []
# Cleaning and adding some fields for each individual scenario's dataframe for concat
for scenario in scenarios :
    i = glob.glob( os.path.join( input_path,graph_variable, '*'.join([ 'ALF',graph_variable.replace('_',''), model, scenario,'.csv' ]) ) )[0]
    tab = pd.read_csv( i, index_col=0 ).ix[begin:end]
    tab['std'] = tab.std(axis=1)
    tab['date'] = tab.index
    tab['scenario']= scenario
    tab = pd.melt(tab, id_vars=["date", "scenario",'std'], var_name="condition")
    frames.append(tab)

#Complete dataframe creation with both scenario in long data form
df = pd.concat(frames, ignore_index= True)
df = df.drop('condition', 1)
df = df.rename(columns = {'scenario':'condition'})
df = df.sort_values(by=['condition','date'])
df = df.reset_index(drop=True)
df = df.groupby(["condition", "date"]).mean().unstack("condition")

errors = df['std'].groupby(df.index // 10 * 10).sum() 
means = df.value.groupby(df.index // 10 * 10).sum()
</code></pre>