title: Networkx weights on edges with cumulative sum
body: <p>I am drawing a networkx graph with weights on edges, which I want to sum weight cumulatively. The code below only gets the last weight of edges but the cumulative sum. There are 5 nodes and 3 edges. The edges are <code>('A', 'B'), ('A', 'D')</code>, and <code>('C', 'E')</code>, and the weight is <code>[1, 1, 1]</code>. What I want the weight is <code>[2, 2, 1]</code> not <code>[1, 1, 1]</code>. Need help. Tks.</p>
  
  <p><strong>1. Create a df</strong></p>
  
  <pre><code>import pandas as pd
  import networkx as nx
  ints = [1] * 5
  a = ['A', 'B', 'C', 'A', 'A']
  b = ['D', 'A', 'E', 'D', 'B']
  df = pd.DataFrame(ints, columns=['weight'])
  df['a'] = a
  df['b'] = b
  df
  
      weight  a   b
  0   1       A   D
  1   1       B   A
  2   1       C   E
  3   1       A   D
  4   1       A   B
  </code></pre>
  
  <p><strong>2. Draw a graph</strong>.</p>
  
  <pre><code>G=nx.from_pandas_dataframe(df, 'a', 'b', ['weight'])
  edges = G.edges() 
  weights = [G[u][v]['weight'] for u,v in edges]
  pos = nx.circular_layout(G)
  nx.draw(G, pos, with_labels=True,  width=weights)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/SroWe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SroWe.png" alt="enter image description here"></a></p>