python - Draw direction graph with overlaps that then splinter off -


working pandas , networkx try , understand/graph purchase flows. ultimate goal visualize purchase paths, overlap common paths, make common paths thicker line, , understand common purchase path. have approximately 20k sets of records. many of records share first few steps in common. integers below map particular skus such 0:"orange", 1:"apple", 2:"banana", etc. each of observations in "column" in pandas dataframe called df. df['observations'] has bunch of records similar below.

here example of of data:

[4,3,5,6,9,17,11.........] [4,3,5,6,9,19,14,19......] [4,3,5,6,9,1,19,22,19....] [7,8,9,4,10,11,1.........] [7,8,9,1,11,10...........] 

all 3 of first few records share first few nodes/edges in path: 4,3,5,6,9, , "splinter" off different directions after that. separate, unconnected part of graph show 7,8,9 common path , splinter off different directions.

i hoping generate sort of graph takes known starting point or in case known set of starting points , draws path these steps. since steps in common refer same path, part of line thicker show several paths share nodes in order.

ultimately i'd have line each of 22 possible start points , map combinations starting points.

this code have far:

title = 'purchase flow tracking'  g=nx.digraph(name=title) routes = df['observations'] edges = [] r in routes:     route_edges = [(r[n],r[n+1]) n in range(len(r)-1)]     g.add_nodes_from(r)     g.add_edges_from(route_edges)     edges.append(route_edges)  print("graph has %d nodes %d edges" %(g.number_of_nodes(),     g.number_of_edges() 

any suggestions appreciated!


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -