-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy path44_arrange_sort.py
More file actions
36 lines (31 loc) · 1.13 KB
/
Copy path44_arrange_sort.py
File metadata and controls
36 lines (31 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
44. Arrange: Sort results by columns
FAST: <1s runtime
Dependencies: py3plex (core)
Demonstrates .arrange() for sorting results (alias for .order_by()).
"""
from py3plex.core import multinet
from py3plex.dsl import Q, L
# Create small multilayer network
net = multinet.multi_layer_network(directed=False)
net.add_nodes([
{'source': 'Alice', 'type': 'social'},
{'source': 'Bob', 'type': 'social'},
{'source': 'Carol', 'type': 'social'},
{'source': 'Dave', 'type': 'social'},
])
net.add_edges([
{'source': 'Alice', 'target': 'Bob', 'source_type': 'social', 'target_type': 'social'},
{'source': 'Alice', 'target': 'Carol', 'source_type': 'social', 'target_type': 'social'},
{'source': 'Alice', 'target': 'Dave', 'source_type': 'social', 'target_type': 'social'},
{'source': 'Bob', 'target': 'Carol', 'source_type': 'social', 'target_type': 'social'},
])
# DSL: Compute degree and arrange by descending order
result = (
Q.nodes()
.compute("degree")
.arrange("degree", desc=True) # Sort by degree descending
.execute(net)
)
print("Nodes sorted by degree (descending):")
print(result.to_pandas())