【问题标题】:seaborn heatmap ufunc 'isnan' not supported for the input types输入类型不支持 seaborn 热图 ufunc 'isnan'
【发布时间】:2020-02-18 12:48:15
【问题描述】:

我收到错误“ufunc 'isnan' not supported for the input types,并且无法根据强制转换规则 ''safe'' 安全地将输入强制转换为任何支持的类型。 我的数据框不包含任何 NaN,并且 dtypes 看起来不错,我什至将 index 设置为 cols 之一。

df = pd.DataFrame({ 'volume':[1.2, 0.3, 1.0, 1.8], 'team': ['A', 'B', 'C', 'D'], 'd' : ['d1', 'd2','d3', 'd4']})
df.set_index("d", inplace=True)
df.isnull().values.any()
df['volume'] = df['volume'].astype(float)
print (df.dtypes)
sns.heatmap(df, annot=True, fmt="g", cmap='viridis')
plt.show()

team       object
volume    float64
dtype: object

我检查了thisthisthis

【问题讨论】:

    标签: python seaborn heatmap


    【解决方案1】:

    您是否正在尝试实现这样的目标?

    team = np.array([['A'], ['B'],['C'], ['D']])
    df = pd.DataFrame({ 'volume':[1.2, 0.3, 1.0, 1.8], 'd' : ['d1', 'd2','d3', 'd4']})
    df.set_index("d", inplace=True)
    df.isnull().values.any()
    df['volume'] = df['volume'].astype(np.float64)
    print (df.dtypes)
    sns.heatmap(df, annot=team, fmt="", cmap='viridis')
    plt.show()
    

    【讨论】:

    • 您的示例有效,但如果我尝试制作方形热图并为 y_axis 设置“团队”,为 x_axis 设置“d”,我得到 df['volume'] = df['volume'] .astype(np.float64)。 IndexError:标量变量的索引无效。
    • 我尝试制作类似于 seaborn heatmap 文档中的示例的东西,又名:ax = sns.heatmap(flights, annot=True, fmt="d"),但我不知道如何他们的df与我的不同
    猜你喜欢
    • 2017-09-17
    • 2021-12-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-10
    • 1970-01-01
    • 2020-07-21
    • 2020-09-29
    • 2023-03-30
    相关资源
    最近更新 更多