Python Pandas Tree Structure
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.)
- 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.
closed as off-topic by Undo♦Jun 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
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.
AbhijeetPython Pandas Tutorial
Tree Structure Syntax
Alex MartelliAlex MartelliI'm happy with treelib. It addresses my problem. Could use a bit more documentation though. But the code is clear.
Terrence BrannonTerrence BrannonAlthough 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.
python-graph seems to be a fairly thorough and complete package, and can export DOT graphs for use with Graphviz.
InactivistInactivistNot 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?
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: