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

e4yzc0pl  于 2024-01-04  发布在  其他
关注(0)|答案(1)|浏览(134)

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

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


的数据
我试着画seaborn箱线图

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

字符串
但它又回来了

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


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

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



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

  1. ---------------------------------------------------------------------------
  2. ValueError Traceback (most recent call last)
  3. ~\AppData\Local\Temp\ipykernel_7004\328781716.py in ?()
  4. 11 df_filtered_sorted = df_filtered.sort_values(by='Class')
  5. 12
  6. ---> 13 class_labels = df_filtered_sorted['Class'].unique()
  7. 14 n_rows = len(class_labels) // 2 + len(class_labels) % 2
  8. 15 n_cols = 2
  9. 16
  10. ~\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)
  11. 2227 dodge=True, fliersize=5, linewidth=None, whis=1.5, ax=None,
  12. 2228 **kwargs
  13. 2229 ):
  14. 2230
  15. -> 2231 plotter = _BoxPlotter(x, y, hue, data, order, hue_order,
  16. 2232 orient, color, palette, saturation,
  17. 2233 width, dodge, fliersize, linewidth)
  18. 2234
  19. ~\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)
  20. 781 def __init__(self, x, y, hue, data, order, hue_order,
  21. 782 orient, color, palette, saturation,
  22. 783 width, dodge, fliersize, linewidth):
  23. 784
  24. --> 785 self.establish_variables(x, y, hue, data, orient, order, hue_order)
  25. 786 self.establish_colors(color, palette, saturation)
  26. 787
  27. 788 self.dodge = dodge
  28. ~\miniconda3\envs\general\lib\site-packages\seaborn\categorical.py in ?(self, x, y, hue, data, orient, order, hue_order, units)
  29. 458 if order is None:
  30. 459 order = []
  31. 460 # Reduce to just numeric columns
  32. 461 for col in data:
  33. --> 462 if variable_type(data[col]) == "numeric":
  34. 463 order.append(col)
  35. 464 plot_data = data[order]
  36. 465 group_names = order
  37. ~\miniconda3\envs\general\lib\site-packages\seaborn\_oldcore.py in ?(vector, boolean_type)
  38. 1498 if pd.api.types.is_categorical_dtype(vector):
  39. 1499 return VariableType("categorical")
  40. 1500
  41. 1501 # Special-case all-na data, which is always "numeric"
  42. -> 1502 if pd.isna(vector).all():
  43. 1503 return VariableType("numeric")
  44. 1504
  45. 1505 # Special-case binary/boolean data, allow caller to determine
  46. ~\miniconda3\envs\general\lib\site-packages\pandas\core\generic.py in ?(self)
  47. 1517 @final
  48. 1518 def __nonzero__(self) -> NoReturn:
  49. -> 1519 raise ValueError(
  50. 1520 f"The truth value of a {type(self).__name__} is ambiguous. "
  51. 1521 "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
  52. 1522 )
  53. ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

qij5mzcb

qij5mzcb1#

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


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

相关问题