networkx

Create, analyze, and visualize complex networks and graphs in Python.

Updated Oct 7, 2022
One-click install
npx skills add https://github.com/tamagusko/linux-cfg --skill networkx-tamagusko
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: networkx
Source: https://github.com/tamagusko/linux-cfg/tree/main/dotfiles/claude/skills/networkx
Command: npx skills add https://github.com/tamagusko/linux-cfg --skill networkx-tamagusko

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires networkx, matplotlib, pandas, numpy, scipy, and includes references (resource) components.

What problem does it solve? Working with network and graph data in Python requires knowing dozens of algorithms, file formats, and visualization options. This Skill provides structured guidance for building graphs, running analyses like centrality and community detection, and producing clear visualizations without searching through documentation. ## Core Features & Use Cases - Graph Creation and Manipulation: Build undirected, directed, and multi-edge graphs from edge lists, DataFrames, NumPy arrays, or synthetic generators like Erdős-Rényi and Barabási-Albert models. - Graph Algorithms: Compute shortest paths, centrality measures, PageRank, clustering coefficients, community detection, maximum flow, and minimum spanning trees. - I/O and Visualization: Read and write GraphML, GML, JSON, CSV, and sparse matrix formats, then render networks with matplotlib layouts or interactive Plotly and PyVis exports. - Use Case: Given a CSV of protein interactions, load it into a graph, detect communities with greedy modularity, rank proteins by betweenness centrality, and export a publication-quality figure. ## Quick Start Use the networkx skill to load my edges.csv file, compute degree centrality for each node, and draw the resulting network with labels.

Frequently Asked Questions about networkx

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a graph from a pandas DataFrame in NetworkX?

Use nx.from_pandas_edgelist with your DataFrame, specifying the source and target columns and optionally edge attributes like weight. This builds a graph directly from tabular edge data without manual add_edge loops.

How to find shortest paths between nodes in NetworkX?

Call nx.shortest_path with source and target nodes, optionally passing a weight attribute for weighted graphs. For all pairs, use nx.all_pairs_shortest_path, and for negative weights use the Bellman-Ford variant.

What graph file formats does NetworkX support?

NetworkX reads and writes edge lists, adjacency lists, GraphML, GML, GEXF, JSON node-link data, and Pajek formats. It also converts to and from pandas DataFrames, NumPy arrays, and SciPy sparse matrices.

Does NetworkX handle large graphs efficiently?

NetworkX loads entire graphs into memory, so very large networks can be slow. Use approximate algorithms with the k parameter for centrality, sparse matrix representations, and fast generators like fast_gnp_random_graph for large sparse graphs.

How do I detect communities in a network with Python?

Import the community module from networkx.algorithms and call greedy_modularity_communities for modularity-based detection or label_propagation_communities for a faster approach. The result is a list of node sets you can color in visualizations.

Why do my NetworkX layouts look different every run?

Force-directed layouts like spring_layout use random initialization, so positions change between runs. Pass a fixed seed parameter, such as nx.spring_layout(G, seed=42), to get reproducible layouts.