使用seabones的heatmap时个别列丢失

在使用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")

这样就解决了。

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值