Package: networkframe
networkframeLightweight representations of networks using Pandas DataFrames.Documentation:https://bdpedigo.github.io/networkframeGitHub:https://github.com/bdpedigo/networkframePyPI:https://pypi.org/project/networkframe/Free software: MITnetworkframeuses Pandas DataFrames to represent networks in a lightweight way.
ANetworkFrameobject is simply a table representing nodes and a table representing
edges, and a variety of methods to make querying and manipulating that data easy.Warning:networkframeis still in early development, so there may be bugs and missing features. Please report any issues you find!ExamplesCreating aNetworkFramefrom scratch:importpandasaspdfromnetworkframeimportNetworkFramenodes=pd.DataFrame({"name":["A","B","C","D","E"],"color":["red","blue","blue","red","blue"],},index=[0,1,2,3,4],)edges=pd.DataFrame({"source":[0,1,2,2,3],"target":[1,2,3,1,0],"weight":[1,2,3,4,5],})nf=NetworkFrame(nodes,edges)print(nf)NetworkFrame(nodes=(5, 2), edges=(5, 3))Selecting a subgraph by node colorred_nodes=nf.query_nodes("color == 'red'")print(red_nodes.nodes)name color
0    A   red
3    D   redSelecting a subgraph by edge weightstrong_nf=nf.query_edges("weight > 2")print(strong_nf.edges)source  target  weight
2       2       3       3
3       2       1       4
4       3       0       5Iterating over subgraphs by node colorforcolor,subgraphinnf.groupby_nodes("color",axis="both"):print(color)print(subgraph.edges)('blue', 'blue')
   source  target  weight
1       1       2       2
3       2       1       4
('blue', 'red')
   source  target  weight
2       2       3       3
('red', 'blue')
   source  target  weight
0       0       1       1
('red', 'red')
   source  target  weight
4       3       0       5Applying node information to edgesnf.apply_node_features("color",inplace=True)print(nf.edges)source  target  weight source_color target_color
0       0       1       1          red         blue
1       1       2       2         blue         blue
2       2       3       3         blue          red
3       2       1       4         blue         blue
4       3       0       5          red          redIsnetworkframeright for you?Pros:Lightweight:NetworkFrameobjects are just two DataFrames, so they're easy to manipulate and integrate with other tools.Interoperable: can output toNetworkX,numpyarrays, andscipysparse arrays.Flexible: can represent directed, undirected, and multigraphs.Familiar: if you're familiar withPandasDataFrames, that is. As much as possible,networkframeuses the same syntax asPandas, but also just gives you access to the underlying tables.Extensible: it's easy to useNetworkFrameas a base graph - for instance, you could make aSpatialNetworkFramethat adds spatial information to the nodes and edges.Cons:No guarantees: sincenetworkframegives you access to the underlyingDataFrames, it doesn't do much validation of the data. This is by design, to keep it lightweight and flexible, but it means you can also mess up aNetworkFrameif you aren't careful (for instance, you could delete the index used to map edges to nodes).Not optimized for graph computations: sincenetworkframeis storing data as simple node and edge tables, it's not optimized for doing actual computations on those graphs (e.g. like searching for shortest paths). A typical workflow would be to usenetworkframeto load and manipulate your data, then convert to a more graph-oriented format likescipysparse matrices orNetworkXfor computations.Room for improvement:Early development: there are likely bugs and missing features. Please report any issues you find!More interoperability:networkframecan currently output toNetworkX,numpy, andscipysparse arrays. It would be nice to be able to read in from these formats in a more convenient way, and ouput to other formats likeigraphorgraph-tool.Graph-type handling:networkframehas mainly been tested on directed graphs, less so for undirected and multigraphs.CreditsThis package was created withCookiecutterand thebdpedigo/cookiecutter-pypackageproject template (which builds on several previous versions).