小编Jiw*_*Kim的帖子

来自带有 NaN 的 Pandas 数据框的 seaborn 热图

嗨,我真的很想创建一个热图,但我很挣扎:

# correlations between undergrad studies and occupation
data_uni = n.groupby(['Q5','Q6'])['Q6'].count().to_frame(name = 'count').reset_index()
# some participants did not answer the question in the survey
data_uni.fillna('Unknown', inplace=True)

data_uni.pivot(index='Q5', columns='Q6', values='count')
plt.figure(1, figsize=(14,10))
sns.heatmap(data_uni, cmap="YlGnBu")
Run Code Online (Sandbox Code Playgroud)

我得到的错误消息是"TypeError: ufunc 'isnan' not supported for the input types, and the input could not be safely coerced to any supported types 根据转换规则 ''safe''"

这是创建热图的正确方法吗?如果是,我做错了什么,如果不是,正确的方法是什么?感谢您的帮助!

python nan heatmap pandas seaborn

4
推荐指数
1
解决办法
6712
查看次数

标签 统计

heatmap ×1

nan ×1

pandas ×1

python ×1

seaborn ×1