首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何处理输入类型不支持的TypeError: ufunc 'isnan‘

如何处理输入类型不支持的TypeError: ufunc 'isnan‘
EN

Data Science用户
提问于 2018-06-12 04:11:39
回答 1查看 86.3K关注 0票数 12
代码语言:javascript
复制
I have dealt with all the Nan values in the features dataframe, then why I am still getting this error? 
代码语言:javascript
复制
sns.heatmap(features, annot=True, annot_kws={"size": 7})
sns.plt.show()
代码语言:javascript
复制
TypeError                                 Traceback (most recent call last)
    <ipython-input-11-534a699b432d> in <module>()
    ----> 1 sns.heatmap(features, annot=True, annot_kws={"size": 7})
          2 sns.plt.show()

    c:\users\jetjo\appdata\local\programs\python\python36\lib\site-packages\seaborn\matrix.py in heatmap(data, vmin, vmax, cmap, center, robust, annot, fmt, annot_kws, linewidths, linecolor, cbar, cbar_kws, cbar_ax, square, xticklabels, yticklabels, mask, ax, **kwargs)
        515     plotter = _HeatMapper(data, vmin, vmax, cmap, center, robust, annot, fmt,
        516                           annot_kws, cbar, cbar_kws, xticklabels,
    --> 517                           yticklabels, mask)
        518 
        519     # Add the pcolormesh kwargs here

    c:\users\jetjo\appdata\local\programs\python\python36\lib\site-packages\seaborn\matrix.py in __init__(self, data, vmin, vmax, cmap, center, robust, annot, fmt, annot_kws, cbar, cbar_kws, xticklabels, yticklabels, mask)
        166         # Determine good default values for the colormapping
        167         self._determine_cmap_params(plot_data, vmin, vmax,
    --> 168                                     cmap, center, robust)
        169 
        170         # Sort out the annotations

    c:\users\jetjo\appdata\local\programs\python\python36\lib\site-packages\seaborn\matrix.py in _determine_cmap_params(self, plot_data, vmin, vmax, cmap, center, robust)
        203                                cmap, center, robust):
        204         """Use some heuristics to set good defaults for colorbar and range."""
    --> 205         calc_data = plot_data.data[~np.isnan(plot_data.data)]
        206         if vmin is None:
        207             vmin = np.percentile(calc_data, 2) if robust else calc_data.min()

    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''
EN

回答 1

Data Science用户

发布于 2018-07-05 21:32:10

您的dataFrame中可能存在类型为object的列。如有可能,将其移除或转换为浮点、int等。

来自海运文件:

数据:矩形数据集

可以强制进入ndarray的2D数据集。如果提供了Pandas,则索引/列信息将用于标记列和行。

所以你可以试试

代码语言:javascript
复制
sns.heatmap(features.drop(['columnName01_OfTypeObject','columnName02_OfTypeObject'],axis=1), annot=True, annot_kws={"size": 7})

这将暂时删除您的列。

票数 11
EN
页面原文内容由Data Science提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://datascience.stackexchange.com/questions/32981

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档