2
respostas

[Bug] erro ao executar o boxplot

Quando utilizo o comando: sns.boxplot(medias_por_filme) aparece o erro :

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/usr/local/lib/python3.9/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   3628             try:
-> 3629                 return self._engine.get_loc(casted_key)
   3630             except KeyError as err:

8 frames
/usr/local/lib/python3.9/dist-packages/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

/usr/local/lib/python3.9/dist-packages/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()

KeyError: 0

The above exception was the direct cause of the following exception:

KeyError                                  Traceback (most recent call last)
<ipython-input-47-3abadd1e2dcf> in <cell line: 1>()
----> 1 sns.boxplot(medias_por_filme)

/usr/local/lib/python3.9/dist-packages/seaborn/categorical.py in boxplot(data, x, y, hue, order, hue_order, orient, color, palette, saturation, width, dodge, fliersize, linewidth, whis, ax, **kwargs)
   2229 ):
   2230 
-> 2231     plotter = _BoxPlotter(x, y, hue, data, order, hue_order,
   2232                           orient, color, palette, saturation,
   2233                           width, dodge, fliersize, linewidth)

/usr/local/lib/python3.9/dist-packages/seaborn/categorical.py in __init__(self, x, y, hue, data, order, hue_order, orient, color, palette, saturation, width, dodge, fliersize, linewidth)
    783                  width, dodge, fliersize, linewidth):
    784 
--> 785         self.establish_variables(x, y, hue, data, orient, order, hue_order)
    786         self.establish_colors(color, palette, saturation)
    787 

/usr/local/lib/python3.9/dist-packages/seaborn/categorical.py in establish_variables(self, x, y, hue, data, orient, order, hue_order, units)
    484                 if hasattr(data, "shape"):
    485                     if len(data.shape) == 1:
--> 486                         if np.isscalar(data[0]):
    487                             plot_data = [data]
    488                         else:

/usr/local/lib/python3.9/dist-packages/pandas/core/series.py in __getitem__(self, key)
    956 
    957         elif key_is_scalar:
--> 958             return self._get_value(key)
    959 
    960         if is_hashable(key):

/usr/local/lib/python3.9/dist-packages/pandas/core/series.py in _get_value(self, label, takeable)
   1067 
   1068         # Similar to Index.get_value, but we do not fall back to positional
-> 1069         loc = self.index.get_loc(label)
   1070         return self.index._get_values_for_loc(self, loc, label)
   1071 

/usr/local/lib/python3.9/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   3629                 return self._engine.get_loc(casted_key)
   3630             except KeyError as err:
-> 3631                 raise KeyError(key) from err
   3632             except TypeError:
   3633                 # If we have a listlike key, _check_indexing_error will raise

KeyError: 0
2 respostas

tentar rodar com o comando: sns.boxplot(medias_por_filme.values)

Eu estava estudando esse modulo e também encontrei o mesmo bug, segui o passo a passo do professor conforme video aula e não estava plotando nada. Ainda bem que consegui encontrar o erro aqui