title: How to perform cluster with weights/density in python? Something like kmeans with weights?
body: <p>My data is like this:</p>
  
  <pre><code>powerplantname, latitude, longitude, powergenerated
  A, -92.3232, 100.99, 50
  B, &lt;lat&gt;, &lt;long&gt;, 10
  C, &lt;lat&gt;, &lt;long&gt;, 20
  D, &lt;lat&gt;, &lt;long&gt;, 40
  E, &lt;lat&gt;, &lt;long&gt;, 5
  </code></pre>
  
  <p>I want to be able to cluster the data into N number of clusters (say 3). Normally I would use a kmeans:</p>
  
  <pre><code>import numpy as np
  
  import matplotlib.pyplot as plt
  from scipy.cluster.vq import kmeans2, whiten
  coordinates= np.array([
             [lat, long],
             [lat, long],
              ...
             [lat, long]
             ])
  x, y = kmeans2(whiten(coordinates), 3, iter = 20)  
  plt.scatter(coordinates[:,0], coordinates[:,1], c=y);
  plt.show()
  </code></pre>
  
  <p>The problem with this is it does not account for any weighting (in this case, my powergenerated value) I want to ideally have my clusters taking the value "powergenerated" into account, trying to keep the clusters not only spatially close, but also have close to relatively equal total powergenerated.</p>
  
  <p>Should I be doing this with kmeans (or some other method)? Or is there something else I should be using for this problem that would be better?</p>