title: How to generate dynamic variable names in pandas dataframe
body: <p>I have one variable in python (value may change) </p>
  
  <pre><code>a = 6
  </code></pre>
  
  <p>Now depending upon the values I have to generate 6 clusters from <code>K-means clustering</code> 
  which gives me following labels in array</p>
  
  <pre><code>y_km
  Out[36]: array([2, 5, 5, 2, 5, 0, 0, 1, 1, 4, 3, 4, 1, 0, 2, 2])
  
  cluster_0 = np.where(y_km == 0)
  cluster_1 = np.where(y_km == 1)
  cluster_2 = np.where(y_km == 2)
  cluster_3 = np.where(y_km == 3)
  cluster_4 = np.where(y_km == 4)
  cluster_5 = np.where(y_km == 5)
  </code></pre>
  
  <p>Then I store the location of every labels in an array to different variables. I want to automate this process so that I don't have to explicitly write code for variable names (<code>cluster_0,cluster_1,cluster_2...)</code></p>
  
  <pre><code>for i in range(a):
      cluster_'%d'%i = np.where(y_km == i)
  </code></pre>
  
  <p>I am doing above but this gives me syntax error.
  Then I am defining one column in a dataframe <code>tsp_data_unique</code></p>
  
  <pre><code>tsp_data_unique['Clusters'] = 'Null'
  </code></pre>
  
  <p>Then I am doing following to assign corresponding cluster labels in dataframe.</p>
  
  <pre><code>tsp_data_unique['Clusters'].iloc[cluster_0] = 'Cluster 1'
  tsp_data_unique['Clusters'].iloc[cluster_1] = 'Cluster 2'
  tsp_data_unique['Clusters'].iloc[cluster_2] = 'Cluster 3'
  tsp_data_unique['Clusters'].iloc[cluster_3] = 'Cluster 4'
  tsp_data_unique['Clusters'].iloc[cluster_4] = 'Cluster 5'
  tsp_data_unique['Clusters'].iloc[cluster_5] = 'Cluster 6'
  </code></pre>
  
  <p>Can I automate the above process. </p>