To create an induced subgraph with nodes selected by some test, you
can use:
SG=G.subgraph( [n for n,attrdict in G.node.items() if attrdict
['type'] == 'X' ] )
Similarly, you can create a subgraph containing only certain edges like:
SG=networkx.Graph( [ (u,v,d) for u,v,d in G.edges(data=True) if d
['weight']>cutoff] )
These two examples use list comprehensions to create lists on the fly.
For more complicated conditions, you might need to construct a list
of nodes
or edges in a loop or in another function and then pass the list to
either
G.subgraph() for induced subgraphs given nodes; or networkx.Graph()
given edges.
Dan
--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to networkx-discu...@googlegroups.com.
To post to this group, send email to networkx...@googlegroups.com.
Visit this group at https://groups.google.com/group/networkx-discuss.
For more options, visit https://groups.google.com/d/optout.
579 True
Name: nlc, dtype: bool
<class 'pandas.core.series.Series'>
<class 'pandas.core.series.Series'>
<class 'pandas.core.series.Series'>
<class 'pandas.core.series.Series'>
<class 'pandas.core.series.Series'>
<class 'pandas.core.series.Series'>
Do you think this is because I create nodes from a pandas dataframe?
All the best,
Kevin