您好:程式码如下:要用资料作地热图,但df.corr()时出现ValueError: could not convert string to float: \'ffwind (培)\'
资料来源部分资料:author,pushes,comments,imagesffwind (培),347,681,4haohao1201 (豪神),1,3,16Black3831372 (男哥是我),5,7,37meokay (我可以),5,8,3maxxxxxx (马克思),106,115,15ReiKuromiya (Rei Kuromiya),7,10,4fack3170 (Jくん),5,7,22
请问,这要如何处理?谢谢
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# 汇入CSV格式的档案
df = pd.read_csv("pttbeauty2.csv", encoding="utf8")
#sns.pairplot(df, kind="scatter", diag_kind="hist")
#plt.show()
#print( df )
sns.heatmap(df.corr(), annot=True, fmt=".2f")
plt.show()
1 个回答
0
zivzhong
iT邦研究生 4 级 ‧ 2025-01-23 01:43:27
最佳解答
试试
df.corr(numeric_only=True)
或者参考:
https://stackoverflow.com/questions/76533178/corr-results-in-valueerror-could-not-convert-string-to-float
-
1 -
-
noway
iT邦研究生 1 级 ‧
2025-01-23 19:15:30
您好:
OK
谢谢!
修改