【问题标题】:TypeError: distplot() got an unexpected keyword argument 'x' (or 'hue')TypeError: distplot() 得到了一个意外的关键字参数“x”(或“hue”)
【发布时间】:2020-09-13 18:10:08
【问题描述】:

当我尝试绘制这个时,我得到了错误-

sns.distplot(X_train, x='Age')                   #Age is a feature in X_train

当我尝试在其中添加 hue 参数时遇到类似的错误

sns.distplot(X_train['Age'], hue=y_train)

TypeError: distplot() got an unexpected keyword argument 'hue'

我做错了什么?这是我尝试代码的地方-

https://seaborn.pydata.org/tutorial/distributions.html

【问题讨论】:

  • displot (no t) - 和 not distplot - 在链接中使用。我怀疑这是一个错字,不幸的是,它的方法名称非常相似。
  • (如果是这样,请考虑关闭 self-voting-to-close 作为拼写错误。)
  • sns.distplot(X_train, x='Age', data=X_train)。第一个参数仅设置要使用的数值数据。 data=... 告诉使用哪个数据框。另请参阅 what is major difference between histogram,countplot and distplot in Seaborn library? 了解类似名称的函数。
  • FWIW,disTplot 已弃用。
  • @user2864740 您能否将其添加为答案,以防其他人遇到同样的问题?此外,事实证明 kaggle 使用的是 seaborn 0.10.0,因此无法识别 displot

标签: data-visualization seaborn


【解决方案1】:

如果有人遇到同样的问题,这就是导致混乱的原因。谢谢@user2864740

sns.distplot() 已弃用。

sns.displot() 是带有huex 参数的新函数。

如果您收到此错误,请更新您的 seaborn 版本。在 cmd -

pip install seaborn --upgrade

在笔记本中添加一个 !点之前

【讨论】:

    猜你喜欢
    • 2018-09-09
    • 2016-09-17
    • 2012-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-08
    相关资源
    最近更新 更多