# Buggy code
def background_gradient(self, cmap="PuBu", low=0, high=0, axis=0, subset=None):
    """
    Color the background in a gradient according to
    the data in each column (optionally row).
    Requires matplotlib.

    .. versionadded:: 0.17.1

    Parameters
    ----------
    cmap: str or colormap
        matplotlib colormap
    low, high: float
        compress the range by these values.
    axis: int or str
        1 or 'columns' for colunwise, 0 or 'index' for rowwise
    subset: IndexSlice
        a valid slice for ``data`` to limit the style application to

    Returns
    -------
    self

    Notes
    -----
    Tune ``low`` and ``high`` to keep the text legible by
    not using the entire range of the color map. These extend
    the range of the data by ``low * (x.max() - x.min())``
    and ``high * (x.max() - x.min())`` before normalizing.
    """
    subset = _maybe_numeric_slice(self.data, subset)
    subset = _non_reducing_slice(subset)
    self.apply(
        self._background_gradient,
        cmap=cmap,
        subset=subset,
        axis=axis,
        low=low,
        high=high,
    )
    return self


# Traceback (KeyError)
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/usr/local/lib/python3.5/site-packages/IPython/core/formatters.py in __call__(self, obj)
339             method = _safe_get_formatter_method(obj, self.print_method)
340             if method is not None:
--> 341                 return method()
342             return None
343         else:

/usr/local/lib/python3.5/site-packages/pandas/core/style.py in _repr_html_(self)
158         Hooks into Jupyter notebook rich display system.
159         '''
--> 160         return self.render()
161
162     def _translate(self):

/usr/local/lib/python3.5/site-packages/pandas/core/style.py in render(self)
259         """
260         self._compute()
--> 261         d = self._translate()
262         # filter out empty styles, every cell will have a class
263         # but the list of props may just be [['', '']].

/usr/local/lib/python3.5/site-packages/pandas/core/style.py in _translate(self)
220                 cs = [DATA_CLASS, "row%s" % r, "col%s" % c]
221                 cs.extend(cell_context.get("data", {}).get(r, {}).get(c, []))
--> 222                 row_es.append({"type": "td", "value": self.data.iloc[r][c],
223                                "class": " ".join(cs), "id": "_".join(cs[1:])})
224                 props = []

/usr/local/lib/python3.5/site-packages/pandas/core/series.py in __getitem__(self, key)
555     def __getitem__(self, key):
556         try:
--> 557             result = self.index.get_value(self, key)
558
559             if not np.isscalar(result):

/usr/local/lib/python3.5/site-packages/pandas/core/index.py in get_value(self, series, key)
1788
1789         try:
-> 1790             return self._engine.get_value(s, k)
1791         except KeyError as e1:
1792             if len(self) > 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

# Fixed code
def background_gradient(self, cmap="PuBu", low=0, high=0, axis=0, subset=None):
    """
    Color the background in a gradient according to
    the data in each column (optionally row).
    Requires matplotlib.

    .. versionadded:: 0.17.1

    Parameters
    ----------
    cmap: str or colormap
        matplotlib colormap
    low, high: float
        compress the range by these values.
    axis: int or str
        1 or 'columns' for colunwise, 0 or 'index' for rowwise
    subset: IndexSlice
        a valid slice for ``data`` to limit the style application to

    Returns
    -------
    self : Styler

    Notes
    -----
    Tune ``low`` and ``high`` to keep the text legible by
    not using the entire range of the color map. These extend
    the range of the data by ``low * (x.max() - x.min())``
    and ``high * (x.max() - x.min())`` before normalizing.
    """
    subset = _maybe_numeric_slice(self.data, subset)
    subset = _non_reducing_slice(subset)
    self.apply(
        self._background_gradient,
        cmap=cmap,
        subset=subset,
        axis=axis,
        low=low,
        high=high,
    )
    return self