title: Create a networkx weighted graph and find the path between 2 nodes with the smallest weight
body: <p>I have a problem involving graph theory. To solve it, I would like to create a weighted graph using networkx. At the moment, I have a dictionnary where each key is a node, and each value is the associated weight (between 10 and 200 000 or so).</p>
  
  <pre><code>weights = {node: weight}
  </code></pre>
  
  <p>I believe I do not need to normalize the weights with networks.
  At the moment, I create a non-weighted graph by adding the edges:</p>
  
  <pre><code>def create_graph(data):
      edges = create_edges(data)
  
      # Create the graph
      G = nx.Graph()
  
      # Add edges
      G.add_edges_from(edges)
  
      return G
  </code></pre>
  
  <p>From what I read, I can add a weight to the edge. However, I would prefer the weight to be applied to a specific node instead of an edge. How can I do that?</p>
  
  <p><strong>Idea:</strong> I create the graph by adding the nodes weighted, and then I add the edges between the nodes.</p>
  
  <pre><code>def create_graph(data, weights):
      nodes = create_nodes(data)
      edges = create_edges(data) # list of tuples
  
      # Create the graph
      G = nx.Graph()
  
      # Add edges
      for node in nodes:
          G.add_node(node, weight=weights[node])
  
      # Add edges
      G.add_edges_from(edges)
  
      return G
  </code></pre>
  
  <p><strong>Is this approach correct?</strong></p>
  
  <p>Next step is to find the path between 2 nodes with the smallest weight. I found this function: <code>networkx.algorithms.shortest_paths.generic.shortest_path</code> which I think is doing the right thing. However, it uses weights on the edge instead of weights on the nodes. Could someone explain me what this function does, what the difference between wieghts on the nodes and weights on the edges is for networkx, and how I could achieve what I am looking for? Thanks :)</p>