如何使用seaborn.clustermap和pandas减少群集数量并识别与其关联的行

时间:2019-02-04 16:45:33

标签: pandas seaborn

我正在尝试生成聚簇的热图,并且希望能够将其减少到X个聚簇,然后返回到我的原始数据帧并用聚簇标识符注释每一行。

这是我到目前为止使用的代码:

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import os

df = pd.read_csv(os.path.join(path, "table.txt"),
                 sep="\t",
                 index_col=0,
           )

cm = sns.clustermap(df)

我已经能够像这样检索行的顺序:

reordered_ind = cm.dendrogram_row.reordered_ind
reordered_ind_names = df.index[reordered_ind]

0 个答案:

没有答案