logo
Loading...

關於直接呼叫df.corr ()會產生error - Cupoy

請問該如何解決df.corr()無法自動轉換數值類別的問題?import seaborn as sn...

關於直接呼叫df.corr ()會產生error

2023/07/20 下午 06:06
特徵選擇
YenCheng Lai
觀看數:23
回答數:1
收藏數:0

請問該如何解決df.corr()無法自動轉換數值類別的問題? import seaborn as sns import matplotlib.pyplot as plt **corr = df.corr()** sns.heatmap(corr) plt.show() 執行後會產生下列Error, ValueError: could not convert string to float: 'RL' 我的python 版本是'3.10.11' pandas 版本是 2.0.1

回答列表

  • 2023/07/20 下午 06:49
    YenCheng Lai
    贊同數:0
    不贊同數:0
    留言數:2

    自問自答,把FIGSIZE設大一點就會看到全部的欄位了 另外再請問, 為什麼我單取數值型資料出來下去跑相關係數,明明df_num有37個column,但heat map卻只有19個column?? num_feature=[] for dtype,col in zip(df.dtypes,df.columns): if dtype=='float64' or dtype=='int64': num_feature.append(col) print(f'{len(num_feature)} Categorical Features : {num_feature}\n') -> 共37個欄位 import seaborn as sns import matplotlib.pyplot as plt corr = df_num.corr() sns.heatmap(corr) plt.show() -> 圖片裡只有19個欄位 謝謝