如何指定Pearson相关热图的数据?

发布于 2025-02-01 10:52:47 字数 1181 浏览 2 评论 0原文

我有一个Pearson相关热图编码了,但是它显示了我不需要的数据框中的数据。

有没有办法指定我想包含哪些列?

预先感谢

“皮尔逊相关热图”

sb.heatmap(df['POPDEN', 'RoadsArea', 'MedianIncome', 'MedianPrice', 'PropertyCount', 'AvPTAI2015', 'PTAL'].corr(), annot=True, fmt='.2f')

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-54-832fc3c86e3e> in <module>
----> 1 sb.heatmap(df['POPDEN', 'RoadsArea', 'MedianIncome', 'MedianPrice', 'PropertyCount', 'AvPTAI2015', 'PTAL'].corr(), annot=True, fmt='.2f')

TypeError: list indices must be integers or slices, not tuple
df.cov().round(3)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-79-34a86e96b161> in <module>
----> 1 df.cov().round(3)

TypeError: cov() missing 1 required positional argument: 'self'

I have a pearson correlation heat map coded, but its showing data from my dataframe which i dont need.

is there a way to specify which columns i'd like to include?

thanks in advance

pearson correlation heatmap

sb.heatmap(df['POPDEN', 'RoadsArea', 'MedianIncome', 'MedianPrice', 'PropertyCount', 'AvPTAI2015', 'PTAL'].corr(), annot=True, fmt='.2f')

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-54-832fc3c86e3e> in <module>
----> 1 sb.heatmap(df['POPDEN', 'RoadsArea', 'MedianIncome', 'MedianPrice', 'PropertyCount', 'AvPTAI2015', 'PTAL'].corr(), annot=True, fmt='.2f')

TypeError: list indices must be integers or slices, not tuple
df.cov().round(3)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-79-34a86e96b161> in <module>
----> 1 df.cov().round(3)

TypeError: cov() missing 1 required positional argument: 'self'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅浅 2025-02-08 10:52:47

您可以在计算相关性之前过滤数据框

sns.heatmap(df[['POPDEN', 'RoadsArea', 'MedianIncome', 'MedianPrice', 'PropertyCount', 'AvPTAI2015', 'PTAL']].corr(), annot=True, fmt='.2f')

You can filter the dataframe before calculating correlation

sns.heatmap(df[['POPDEN', 'RoadsArea', 'MedianIncome', 'MedianPrice', 'PropertyCount', 'AvPTAI2015', 'PTAL']].corr(), annot=True, fmt='.2f')
和影子一齐双人舞 2025-02-08 10:52:47

#对于多列选择,请使用双方括号。
我希望这会起作用

sb.heatmap(df[['POPDEN', 'RoadsArea', 'MedianIncome', 'MedianPrice', 'PropertyCount', 'AvPTAI2015', 'PTAL']].corr(), annot=True, fmt='.2f')

#for multiple column selection use double square brackets.
I hope this would work

sb.heatmap(df[['POPDEN', 'RoadsArea', 'MedianIncome', 'MedianPrice', 'PropertyCount', 'AvPTAI2015', 'PTAL']].corr(), annot=True, fmt='.2f')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文