【发布时间】:2017-09-17 07:11:34
【问题描述】:
当我尝试绘制 seaborn 热图时出现错误
TypeError: 输入类型不支持 ufunc 'isnan',根据转换规则 ''safe'' 无法安全地将输入强制转换为任何支持的类型
我的代码如下
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df = pd.read_table(r"C:\Results.CST", sep='\s+',header=11, engine = 'python')
df2 = cridim[['Bottom','Location_X','Location_Y',]] # Bottom , location X and Location Y are my column labels
df3 = df2.pivot('Location_X','Location_Y','Bottom') # create pivot table for results
plt.figure(figsize=(15,15))
pivot_table = df3
plt.xlabel('X',size = 10)
plt.ylabel('Y',size = 10)
plt.title('btm CD',size = 10)
sns.heatmap(pivot_table, annot=False, fmt=".1f", linewidths = 0.5, square = True, cmap = 'RdYlBu', vmin=2900, vmax = 3500)
plt.show()
在我的数据中由77行77列组成,其中只有651个有数据,其他空坐标在dataframe中表示为None
seaborn heatmap 可以绘制多少数据有限制吗?
我不知道为什么会出现上述错误,我已将其写入 csv 文件,结果正常。
此外,我尝试将值替换为 '0' 和空字符串,但它仍然返回 Typeerror
【问题讨论】:
-
问题解决,我发现在列中,有一个 NaN 值,使用 dropna 和 fillna 不起作用,我决定全部使用数字(在这里@ 987654321@)
标签: python-3.x pandas seaborn