为什么无法将字符串转换为浮点数:'Switzerland'

问题描述 投票:0回答:1

我试图做我的实验室练习,但出现错误,但我不知道问题是什么以及在哪里修复它。谁能告诉我问题是什么,以便我可以解决它?这是代码:

f, ax = plt.subplots (figsize = (10, 10))
sns.heatmap (df.corr (), annot = True, linewidths = .5, fmt = '.1f', ax=ax)
plt.show ()

然后出现以下输出:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[7], line 2
      1 f, ax = plt.subplots (figsize = (10, 10))
----> 2 sns.heatmap (df.corr (), annot = True, linewidths = .5, fmt = '.1f', ax=ax)
      3 plt.show ()

ValueError: could not convert string to float: 'Switzerland'
jupyter-notebook anaconda
1个回答
0
投票

看来您可能已将

sns
定义为不正确的内容,因为您从未在上面的示例代码中定义过它。我假设您之前在代码中定义了
sns

© www.soinside.com 2019 - 2024. All rights reserved.