首页 文章

seaborn排除聚类中的列

提问于
浏览
0

我有一个包含200行和97列的数据集,我将其存储为pandas数据帧 .

我正在用seaborn绘制这个数据帧,使用clustermap,如下所示:

from matplotlib.colors import ListedColormap

sns.set(rc={'axes.facecolor':'white', 'figure.facecolor':'white'})
cmap=ListedColormap(["white", "lightgray", "blue", "red", "cornflowerblue", "darkcyan", "pink", "violet"])
g = sns.clustermap(df,method="complete", metric="hamming",row_cluster=True, 
col_cluster=False, figsize=(10, 20), cmap=cmap)
plt.setp(g.ax_heatmap.get_yticklabels(), rotation=0) 
plt.show()

但是,我刚刚意识到我想像这样绘制它,但我不希望我的数据帧的两个第一列包含在距离计算中 .

关于如何实现这一目标的建议?

谢谢!

1 回答

  • 1

    使用 iloc 进行修剪

    from matplotlib.colors import ListedColormap
    
    sns.set(rc={'axes.facecolor':'white', 'figure.facecolor':'white'})
    cmap=ListedColormap(["white", "lightgray", "blue", "red", "cornflowerblue", "darkcyan", "pink", "violet"])
    g = sns.clustermap(
        df.iloc[:, 2:], method="complete", metric="hamming", row_cluster=True,
        col_cluster=False, figsize=(10, 20), cmap=cmap)
    plt.setp(g.ax_heatmap.get_yticklabels(), rotation=0) 
    plt.show()
    

相关问题