【问题标题】:ValueError: Could not interpret input in seabornValueError:无法解释 seaborn 中的输入
【发布时间】:2020-11-15 12:48:57
【问题描述】:

我有这个数据框:

df = {'DATE':  [43390, 43599, 43605, 43329, 43440],
      'STORE': [1, 1, 1, 2, 2],
      'LYLTY_CARD_NBR': [1000, 1307, 1343, 2373, 2426],
      'TXN_ID': [1, 348, 383, 974, 1038],
      'PROD_QTY': [2, 3, 2, 5, 3],
      'TOT_SALES': [6.0, 6.3, 2.9, 15.0, 13.8]}

transac = pd.DataFrame(df)

    DATE    STORE   LYLTY_CARD_NBR  TXN_ID  PROD_QTY    TOT_SALES
0   43390   1         1000             1           2    6.0
1   43599   1         1307             348         3    6.3
2   43605   1         1343             383         2    2.9
3   43329   2         2373             974         5    15.0
4   43440   2         2426             1038        3    13.8

当我尝试从 TOT_SALES 列的 seaborn 绘制箱线图时,出现此错误。列的类型是 float64。我对 matplotlib 进行了同样的尝试,但它对 seaborn 有效:

sns.boxplot(y='TOT_SALES', df=transac)

ValueError                                Traceback (most recent call last)
<ipython-input-16-29f35d075db2> in <module>
----> 1 sns.boxplot(y='TOT_SALES', df=transac)

~\Anaconda3\lib\site-packages\seaborn\categorical.py in boxplot(x, y, hue, data, order, hue_order, orient, color, palette, saturation, width, dodge, fliersize, linewidth, whis, ax, **kwargs)
   2239     plotter = _BoxPlotter(x, y, hue, data, order, hue_order,
   2240                           orient, color, palette, saturation,
-> 2241                           width, dodge, fliersize, linewidth)
   2242 
   2243     if ax is None:

~\Anaconda3\lib\site-packages\seaborn\categorical.py in __init__(self, x, y, hue, data, order, hue_order, orient, color, palette, saturation, width, dodge, fliersize, linewidth)
    441                  width, dodge, fliersize, linewidth):
    442 
--> 443         self.establish_variables(x, y, hue, data, orient, order, hue_order)
    444         self.establish_colors(color, palette, saturation)
    445 

~\Anaconda3\lib\site-packages\seaborn\categorical.py in establish_variables(self, x, y, hue, data, orient, order, hue_order, units)
    150                 if isinstance(var, str):
    151                     err = "Could not interpret input '{}'".format(var)
--> 152                     raise ValueError(err)
    153 
    154             # Figure out the plotting orientation

ValueError: Could not interpret input 'TOT_SALES'

问题出在哪里?

【问题讨论】:

  • 你能展示你使用 seaborn 的绘图代码吗?
  • 只为我工作过 ax = seaborn.boxplot(y=transac['TOT_SALES'])
  • @pavel 我加了斧头,但我也不工作。我看不出问题出在哪里
  • @pavel 我发现了问题所在。我在绘图代码中键入 df 而不是 data 。谢谢!
  • 我投票结束这个问题,因为根据 OP,它是由拼写错误引起的。

标签: python pandas seaborn boxplot


【解决方案1】:

错误的来源是您将 transac 作为 df seaborn 不使用的参数。将其作为 data 传递:

sns.boxplot(y='TOT_SALES', data=transac);

【讨论】:

    猜你喜欢
    • 2019-01-12
    • 1970-01-01
    • 2021-08-01
    • 2019-02-14
    • 2015-12-30
    • 2022-11-23
    • 2020-10-18
    • 2018-12-28
    相关资源
    最近更新 更多