April 2019
Beginner
190 pages
4h 54m
English
This section will give examples of working with spatial data in NetworkX. In particular, the examples analyze direct flights in the continental US in 2018. In this network, nodes represent airports and edges represent passenger flow between those airports. This is a spatial network because the airports correspond to geographic locations and the distance spanned by each edge is relevant when analyzing the network. The following code loads the network row by row:
# Load data file into networkfrom pathlib import Pathdata_dir = Path('.') / 'data'G_air = nx.Graph()with open(data_dir / 'BTS2018' / 'carrier.csv') as f: # Skip header next(f) # Loop through data rows for row in f: count, v, w, year, month = row.strip().split(',') ...Read now
Unlock full access