Time based filtering

Intermediate Network Analysis in Python

Eric Ma

Data Carpentry instructor and author of nxviz package

Key concepts

  • Filtering graphs

  • Datetime

  • Visualization

Intermediate Network Analysis in Python

Filtering edges

list(G.edges(data=True))[0:5]
[(0, 17, {'sale_count': 1}),
 (0, 18, {'sale_count': 1}),
 (0, 19, {'sale_count': 2}),
 (0, 12, {'sale_count': 14}),
 (0, 13, {'sale_count': 9})]
[(u, v) for u, v, d in G.edges(data=True) if d['sale_count'] >= 10]
[(0, 12), (1, 19), (5, 16), (6, 13), (7, 17), (7, 19), (8, 18)]
Intermediate Network Analysis in Python

Datetime

from datetime import datetime, timedelta

year = 2011 month = 11 day1 = 10 day2 = 6
date1 = datetime(year, month, day1) date2 = datetime(year, month, day2)
date1 > date2
True
Intermediate Network Analysis in Python

Graph visualization

from nxviz import circos
c = circos(G, group_by='bipartite',
              node_color_by='bipartite')

plt.show()

ch4-2.019.png

Intermediate Network Analysis in Python

Let's practice!

Intermediate Network Analysis in Python

Preparing Video For Download...