Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用pandas在Python中创建和绘制层次树_Python_Matplotlib_Pandas_Tree_Hierarchical Clustering - Fatal编程技术网

使用pandas在Python中创建和绘制层次树

使用pandas在Python中创建和绘制层次树,python,matplotlib,pandas,tree,hierarchical-clustering,Python,Matplotlib,Pandas,Tree,Hierarchical Clustering,因此,我在pandas数据框架中存储了分层信息,我想基于这些信息构建并可视化一个分层树 例如,我的数据框中的一行具有列标题- [‘门’、‘类’、‘目’、‘科’、‘属’、‘种’、‘亚种’] 我想用每一行创建一棵树,其中所有的“亚种”都是唯一的字符串,应该是树中的叶子。有人能告诉我最好的方法/包装等吗。。。为什么要这么做?理想情况下,输出将是matplotlib对象。提前谢谢你 使用groupby,您可以轻松地在层次索引中获取它们: taxons = ['Phylum','Class','Order

因此,我在pandas数据框架中存储了分层信息,我想基于这些信息构建并可视化一个分层树

例如,我的数据框中的一行具有列标题- [‘门’、‘类’、‘目’、‘科’、‘属’、‘种’、‘亚种’]


我想用每一行创建一棵树,其中所有的“亚种”都是唯一的字符串,应该是树中的叶子。有人能告诉我最好的方法/包装等吗。。。为什么要这么做?理想情况下,输出将是matplotlib对象。提前谢谢你

使用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
从这里开始,我还试图做一个有意义的情节来展示这种等级制度 (见附件)