TypeError:输入类型不支持ufunc'isnan'-seaborn Heatmap [英] TypeError: ufunc 'isnan' not supported for the input types, - seaborn Heatmap

查看:1155
本文介绍了TypeError:输入类型不支持ufunc'isnan'-seaborn Heatmap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试绘制海洋热图时出现错误

I am getting the error when i try to plot a seaborn heatmap

TypeError:输入类型不支持ufunc'isnan',并且根据强制转换规则"safe",不能将输入安全地强制转换为任何受支持的类型

TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''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个具有数据,其他空坐标在数据框中表示为无".

In my data consist of 77 rows and 77 columns, of which only 651 have data, the others empty coordinates are indicated as None in the dataframe

海洋热图可以绘制多少数据是否有限制?

Is there a limitation of how many data can seaborn heatmap can plot?

我不确定为什么会出现上述错误,我已经将其写入了一个csv文件中,结果还可以.

I am not sure why am i getting the above error, I have written it to a csv file and it turns out alright.

此外,我尝试将值替换为'0'并为空字符串,但它仍返回Typeerror

in addition, I have try to replace the values to '0' and empty string but it still return the Typeerror

推荐答案

当您尝试绘制带有seaborn的图并且某些值不是数字时,会发生此错误.

This error happens when you are trying to draw a graph with seaborn, and some of the values are not numeric.

seaborn尝试将所有数据强制转换为数字,但有时会出现此错误.解决方案是确保您的数据中没有NaN或字符串.

seaborn tries to coerce all data into numbers, but sometimes this error arises. The solution is that you make sure that you don't have NaNs or strings in your data.

在调用seaborn图形库之前,请尝试使用df.astype(float).确保您也没有任何NaN.

Try using df.astype(float) before calling the seaborn graph library. Make sure that you also don't have any NaNs.

这篇关于TypeError:输入类型不支持ufunc'isnan'-seaborn Heatmap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆