在使用heatmap时,发现有一列丢掉了。
import seaborn as sns
plt.figure(figsize=(16,12))
sns.heatmap(df.iloc[:,1:].corr(),annot=True,fmt=".2f")
plt.show()
【解决方法】
检查一下字段的数据类型,很可能是object类型:
df.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 6554 entries, 0 to 6553 Data columns (total 19 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 off_date 6554 non-null object 1 type 6554 non-null int64 2 branch 6554 non-null int64 3 is_charging 6554 non-null int64 4 lm_is_charging 6554 non-null int64 5 speed 6554 non-null int64 6 level 6554 non-null int64 7 payment_turn 6554 non-null int64 8 sourse_type 6554 non-null int64 9 payment_type 6554 non-null int64 10 packages_type 6554 non-null int64 11 pro_state 6554 non-null int64 12 is_big_deal 6554 non-null int64 13 is_back 6554 non-null int64 14 is_mid_high 6554 non-null int64 15 lsm_is_change_package 6554 non-null int64 16 effective_term 6554 non-null object 17 off_month 6554 non-null int64 18 off_ten_days 6554 non-null int64 dtypes: int64(17), object(2) memory usage: 973.0+ KB
发现effective_term字段是object类型,检查该列数据中是否有非数字数据,若有,要先进行处理再转换为数字。转换数据类型的方法可以参考这篇博文。
df["effective_term"].astype("int")
这样就解决了。