04.08.2019»»воскресенье

Python Pandas Tree Structure

04.08.2019
    69 - Comments

Are there any python libraries for data trees?

I mean a tree as a general data structure, not just an xml tree.(Like in this question, but in python.)

Community
uhbif19uhbif19
  • In this video, you will understand the data structures of the Python library Pandas. In this video, you will understand the data structures of the Python library Pandas. Skip navigation.
  • Python – Pandas Data Structure (series, panel & Dataframe) Pandas in Python deals with three data structures namely. Series – 1D labeled homogeneous array, sizeimmutable. Data Frames – 2D labeled, size-mutable tabular structure with heterogenic columns. Panel – 3D labeled size mutable array.

Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas where method is used to check a data frame for one or more condition.

1,8702 gold badges20 silver badges37 bronze badges

closed as off-topic by UndoJun 6 '16 at 4:58

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • 'Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.' – Undo
If this question can be reworded to fit the rules in the help center, please edit the question.

5 Answers

pypi, the Python Package Index, suggests tinytree, treedict, caxes, pyavl... these are just the top few after filtering away the many accidental hits (which point to specific tree such as XML ones, AST ones, etc, etc;-). If you clarify what you want to do with your trees it may be easier to suggest a specific package.

Abhijeet

Python Pandas Tutorial

5,5551 gold badge49 silver badges64 bronze badges

Tree Structure Syntax

Alex MartelliAlex Martelli
649k132 gold badges1057 silver badges1288 bronze badges

I'm happy with treelib. It addresses my problem. Could use a bit more documentation though. But the code is clear.

Terrence BrannonTerrence Brannon
1,8284 gold badges25 silver badges49 bronze badges

Although the ETE library seems to be originally developed to work with Phylogenetic trees, it implements many general features to work with any type of hierarchical tree structures, including programmatic tree drawing and visualization.

There is a comprehensive tutorial and a reference guide, in case you want to explore it.

Marc104Marc104

python-graph seems to be a fairly thorough and complete package, and can export DOT graphs for use with Graphviz.

InactivistInactivist
5,3953 gold badges22 silver badges39 bronze badges
TeddyTeddy
5,0121 gold badge18 silver badges32 bronze badges

Not the answer you're looking for? Browse other questions tagged pythontree or ask your own question.

I have a pandas DataFrame of unique rows which looks something like this:

Columns of df are ordered in parent-child linear relation, wherein column O is level 1, column B is level 2 and so on. The intention is to convert this df into a tree like structure for navigation purposes, which would look something like this:

Filtering on each column's each value in df (as parent) then copying all unique values of remaining columns on the right as child seems like a bad way to achieve this.

Is there an efficient way?

Mohi
MohiMohi

Pandas Python Download

1 Answer

As I mentioned, we have this way to achieve this:

Filtering on each column's each value in df (as parent) then copying all unique values of remaining columns on the right as child seems like a bad way to achieve this.

And the solution with same logic is here:

MohiMohi
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Pandas

Not the answer you're looking for? Browse other questions tagged pythondataframetree or ask your own question.