Skip to content

Conversation

@Zsailer
Copy link
Owner

@Zsailer Zsailer commented Oct 3, 2019

Adds a .phylo.prune() method.

The function takes a simple kwarg. The key is the column name in the DataFrame and the value is row's value at that column.

Example:

In the example below, prune a node "3" by passing in id='3'. id is the column name. '3' is the value.

Before:

df.phylo.display()

Screen Shot 2019-10-03 at 1 54 10 PM

After:

df.phylo.prune(id='3')
df.phylo.display

Screen Shot 2019-10-03 at 1 54 18 PM

@Zsailer
Copy link
Owner Author

Zsailer commented Oct 3, 2019

@harmsm and @jharman25

Comment on lines +39 to +46
node = tree.find_node_with_label(val)

# Get all descendant nodes
descendants = list(node.postorder_iter())

# Remove them from dataframe
nodes_to_rm = [d.label for d in descendants]
return df.loc[~df[col].isin(nodes_to_rm)] No newline at end of file
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@harmsm Here's the magic.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

postorder_iter is a generator that loops over descendant nodes from any other node

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants