Skip to content

Commit 0a4c6b7

Browse files
committed
better docs
1 parent b655056 commit 0a4c6b7

File tree

5 files changed

+311
-20
lines changed

5 files changed

+311
-20
lines changed

README.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,105 @@ Lightweight representations of networks using Pandas DataFrames.
1616
A `NetworkFrame` object is simply a table representing nodes and a table representing
1717
edges, and a variety of methods to make querying and manipulating that data easy.
1818

19+
## Examples
20+
21+
Creating a `NetworkFrame` from scratch:
22+
23+
```python
24+
import pandas as pd
25+
26+
from networkframe import NetworkFrame
27+
28+
nodes = pd.DataFrame(
29+
{
30+
"name": ["A", "B", "C", "D", "E"],
31+
"color": ["red", "blue", "blue", "red", "blue"],
32+
},
33+
index=[0, 1, 2, 3, 4],
34+
)
35+
edges = pd.DataFrame(
36+
{
37+
"source": [0, 1, 2, 2, 3],
38+
"target": [1, 2, 3, 1, 0],
39+
"weight": [1, 2, 3, 4, 5],
40+
}
41+
)
42+
43+
nf = NetworkFrame(nodes, edges)
44+
print(nf)
45+
```
46+
47+
```text.python.console
48+
NetworkFrame(nodes=(5, 2), edges=(5, 3))
49+
```
50+
51+
Selecting a subgraph by node color
52+
53+
```python
54+
red_nodes = nf.query_nodes("color == 'red'")
55+
print(red_nodes.nodes)
56+
```
57+
58+
```text.python.console
59+
name color
60+
0 A red
61+
3 D red
62+
```
63+
64+
Selecting a subgraph by edge weight
65+
66+
```python
67+
strong_nf = nf.query_edges("weight > 2")
68+
print(strong_nf.edges)
69+
```
70+
71+
```text.python.console
72+
source target weight
73+
2 2 3 3
74+
3 2 1 4
75+
4 3 0 5
76+
```
77+
78+
Iterating over subgraphs by node color
79+
80+
```python
81+
for color, subgraph in nf.groupby_nodes("color", axis="both"):
82+
print(color)
83+
print(subgraph.edges)
84+
```
85+
86+
```text.python.console
87+
('blue', 'blue')
88+
source target weight
89+
1 1 2 2
90+
3 2 1 4
91+
('blue', 'red')
92+
source target weight
93+
2 2 3 3
94+
('red', 'blue')
95+
source target weight
96+
0 0 1 1
97+
('red', 'red')
98+
source target weight
99+
4 3 0 5
100+
```
101+
102+
Applying node information to edges
103+
104+
```python
105+
nf.apply_node_features("color", inplace=True)
106+
print(nf.edges)
107+
```
108+
109+
```text.python.console
110+
source target weight source_color target_color
111+
0 0 1 1 red blue
112+
1 1 2 2 blue blue
113+
2 2 3 3 blue red
114+
3 2 1 4 blue blue
115+
4 3 0 5 red red
116+
```
117+
19118
## Is `networkframe` right for you?
20119

21120
**Pros:**

docs/examples/readme_example.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# %%
2+
import pandas as pd
3+
4+
from networkframe import NetworkFrame
5+
6+
nodes = pd.DataFrame(
7+
{
8+
"name": ["A", "B", "C", "D", "E"],
9+
"color": ["red", "blue", "blue", "red", "blue"],
10+
},
11+
index=[0, 1, 2, 3, 4],
12+
)
13+
edges = pd.DataFrame(
14+
{
15+
"source": [0, 1, 2, 2, 3],
16+
"target": [1, 2, 3, 1, 0],
17+
"weight": [1, 2, 3, 4, 5],
18+
}
19+
)
20+
21+
nf = NetworkFrame(nodes, edges)
22+
print(nf)
23+
24+
# %%
25+
26+
# Select a subgraph by node color
27+
red_nodes = nf.query_nodes("color == 'red'")
28+
print(red_nodes.nodes)
29+
30+
# %%
31+
32+
# Select a subgraph by edge weight
33+
strong_nf = nf.query_edges("weight > 2")
34+
print(strong_nf.edges)
35+
36+
# %%
37+
38+
# Iterate over subgraphs by node color
39+
for color, subgraph in nf.groupby_nodes("color", axis="both"):
40+
print(color)
41+
print(subgraph.edges)
42+
43+
# %%
44+
45+
# Apply node information to edges
46+
# (e.g. to color edges by the color of their source node)
47+
48+
nf.apply_node_features("color", inplace=True)
49+
print(nf.edges)

mkdocs.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ plugins:
7171
- https://docs.python.org/3/objects.inv
7272
- https://pandas.pydata.org/pandas-docs/stable/objects.inv
7373
- https://networkx.org/documentation/stable/objects.inv
74+
- https://docs.scipy.org/doc/scipy/objects.inv
7475
options:
7576
show_source: false
7677
docstring_style: numpy
77-
docstring_section_style: table # list, table, spacy
78+
docstring_section_style: spacy # list, table, spacy
7879
docstring_options:
7980
ignore_init_summary: false
8081
merge_init_into_class: true
@@ -89,7 +90,7 @@ plugins:
8990
summary: true
9091
show_if_no_docstring: false
9192
show_docstring_attributes: false
92-
annotations_path: source
93+
annotations_path: brief
9394
show_signature: true
9495
separate_signature: false
9596
show_signature_annotations: false

0 commit comments

Comments
 (0)