pandas 获取“ValueError:The truth value of a Series is ambiguous”from seaborn boxplot of Restrame [关闭]

e4yzc0pl  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(103)

**已关闭。**此问题为not reproducible or was caused by typos。目前不接受回答。

这个问题是由一个错字或一个无法再重现的问题引起的。虽然类似的问题可能在这里是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
20天前关闭。
Improve this question
我有一个pandas框架


的数据
我试着画seaborn箱线图

sns.boxplot(data=df_filtered[df_filtered['Class'] == 1].drop(['Plot', 'Class'], axis=1))

字符串
但它又回来了

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().


问题是,我在不同的数据上使用了完全相同的命令,它工作得很好。我已经用这种方式制作了许多箱线图。此外,matplotlib版本的工作原理:

plt.boxplot(x=df_filtered[df_filtered['Class'] == 1].drop(['Plot', 'Class'], axis=1))



显然,我可以只使用matplotlib命令,但这样我就必须重做所有以前的图,这是不好的,我想知道到底出了什么问题。这是一个bug,还是我错过了什么?
编辑:以下是完整的traceback:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_7004\328781716.py in ?()
     11 df_filtered_sorted = df_filtered.sort_values(by='Class')
     12 
---> 13 class_labels = df_filtered_sorted['Class'].unique()
     14 n_rows = len(class_labels) // 2 + len(class_labels) % 2
     15 n_cols = 2
     16 

~\miniconda3\envs\general\lib\site-packages\seaborn\categorical.py in ?(data, x, y, hue, order, hue_order, orient, color, palette, saturation, width, dodge, fliersize, linewidth, whis, ax, **kwargs)
   2227     dodge=True, fliersize=5, linewidth=None, whis=1.5, ax=None,
   2228     **kwargs
   2229 ):
   2230 
-> 2231     plotter = _BoxPlotter(x, y, hue, data, order, hue_order,
   2232                           orient, color, palette, saturation,
   2233                           width, dodge, fliersize, linewidth)
   2234 

~\miniconda3\envs\general\lib\site-packages\seaborn\categorical.py in ?(self, x, y, hue, data, order, hue_order, orient, color, palette, saturation, width, dodge, fliersize, linewidth)
    781     def __init__(self, x, y, hue, data, order, hue_order,
    782                  orient, color, palette, saturation,
    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 
    788         self.dodge = dodge

~\miniconda3\envs\general\lib\site-packages\seaborn\categorical.py in ?(self, x, y, hue, data, orient, order, hue_order, units)
    458                 if order is None:
    459                     order = []
    460                     # Reduce to just numeric columns
    461                     for col in data:
--> 462                         if variable_type(data[col]) == "numeric":
    463                             order.append(col)
    464                 plot_data = data[order]
    465                 group_names = order

~\miniconda3\envs\general\lib\site-packages\seaborn\_oldcore.py in ?(vector, boolean_type)
   1498     if pd.api.types.is_categorical_dtype(vector):
   1499         return VariableType("categorical")
   1500 
   1501     # Special-case all-na data, which is always "numeric"
-> 1502     if pd.isna(vector).all():
   1503         return VariableType("numeric")
   1504 
   1505     # Special-case binary/boolean data, allow caller to determine

~\miniconda3\envs\general\lib\site-packages\pandas\core\generic.py in ?(self)
   1517     @final
   1518     def __nonzero__(self) -> NoReturn:
-> 1519         raise ValueError(
   1520             f"The truth value of a {type(self).__name__} is ambiguous. "
   1521             "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
   1522         )

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

qij5mzcb

qij5mzcb1#

我正要粘贴数据时,我看到了两个列的名称相同的框架。当我改变了最后一列的名称,删除重复,它的工作。


的数据
我不知道是否需要做任何事情与此信息。谢谢大家的帮助。

相关问题