【问题标题】:Creating and graphing Hierarchical Trees in Python with pandas使用 pandas 在 Python 中创建和绘制层次树
【发布时间】:2015-10-09 19:09:35
【问题描述】:

所以我在 pandas DataFrame 中存储了分层信息,我想根据这些信息构建和可视化分层树。

例如,我的 DataFrame 中的一行具有列标题 — ['门','类','目','科','属','种','亚种']

我想为每一行创建一棵树,其中所有“亚种”都是唯一的字符串,应该是树中的叶子。有人可以指出我这样做的最佳方法/包等吗?理想情况下,输出将是一个 matplotlib 对象。提前谢谢!

【问题讨论】:

    标签: python matplotlib pandas tree hierarchical-clustering


    【解决方案1】:

    您可以使用 groupby 轻松地将它们放入分层索引中:

    taxons = ['Phylum','Class','Order','Family','Genus','Species','Subspecies']
    hierarchical_df = my_dataframe.groupby(taxons).sum() #sum or whatever is most appropiate for your data
    

    从那里开始,我也在尝试制作一个有意义的情节来展示这种层次结构 (见Hierarchic pie/donut chart from Pandas DataFrame using bokeh or matplotlib?

    【讨论】:

      猜你喜欢
      • 2011-01-19
      • 2018-12-19
      • 1970-01-01
      • 2011-03-10
      • 1970-01-01
      • 2017-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多