【问题标题】:Future warning message [duplicate]未来的警告信息 [重复]
【发布时间】:2022-01-02 11:03:13
【问题描述】:

如何才能消除此警告?

C:\ProgramData\Anaconda3\lib\site-packages\seaborn_decorators.py:36:FutureWarning:将以下变量作为关键字 arg 传递:x。从版本 0.12 开始,唯一有效的位置参数将是 data,并且在没有显式关键字的情况下传递其他参数将导致错误或误解。 警告.warn(enter image description here

sns.countplot(ex_emp['dept'])    
plt.title('Department of Employees Who Left')    
plt.figure(figsize=(10,5))    
plt.savefig('ex_dept.png', bbox_inches='tight')    
plt.show()

【问题讨论】:

  • 警告告诉你在未来的 seaborn 版本中你需要写sns.countplot(x=ex_emp['dept'])。我们鼓励你现在已经这样做了。如果没有正确的关键字,它很快就会混淆想要哪个情节。

标签: python seaborn


【解决方案1】:

该警告似乎只是表明在未来的seaborn 版本中将不允许使用位置参数(data 除外)。代码现在可以运行,但是除了删除警告之外,通过调整它可以确保在升级seaborn 时它会继续运行。

根据the sns.countplot() documentation(以及警告消息本身),您应该通过关键字传递的参数是x。以下行需要调整:

sns.countplot(ex_emp['dept'])

如果我没有误解文档,以下两种替换都应该有效:

# 1st option
sns.countplot(x=ex_emp['dept'])

# 2nd option
sns.countplot(x='dept', data=ex_emp)

以防万一,试试看吧!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-10
    • 1970-01-01
    • 2019-10-31
    • 2018-06-24
    • 2018-09-27
    • 2010-11-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多