title: Rename columns while pivoting from long to wide dataframe in Pandas
body: <p>I would like to convert <code>df</code> below from long to wide so that <code>data</code> for each <code>id</code> is present in a row. Currently there are 10000 rows for each unique <code>id</code>.</p>
  <p><code>df</code>:</p>
  <pre><code>    id  data
  0   20  9.5
  1   20  9.5
  2   20  8.5
  ... ... ...
  
  171372  118 1.0
  171373  118 1.2
  171374  118 1.2
  </code></pre>
  <p>expected output:</p>
  <pre><code>     d0   d1   d2  ... 
  id
  20   9.5  9.5  8.5
  118  1.0  1.2  1.2
  </code></pre>
  <p>I tried:</p>
  <pre><code>df.pivot(index='id', columns = [i for i in range(0,10000)] , values='data')
  </code></pre>
  <p>It caught error:</p>
  <pre><code>---------------------------------------------------------------------------
  KeyError                                  Traceback (most recent call last)
  ~\AppData\Roaming\Python\Python38\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
     2888             try:
  -&gt; 2889                 return self._engine.get_loc(casted_key)
     2890             except KeyError as err:
  
  pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
  
  pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
  
  pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
  
  pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
  
  KeyError: 0
  
  The above exception was the direct cause of the following exception:
  
  KeyError                                  Traceback (most recent call last)
  &lt;ipython-input-413-892c34c9ffea&gt; in &lt;module&gt;
        1 
        2 
  ----&gt; 3 df.pivot(index='id', columns = [i for i in range(0,10000)] , values='data')
  
  ~\AppData\Roaming\Python\Python38\site-packages\pandas\core\frame.py in pivot(self, index, columns, values)
     6665         from pandas.core.reshape.pivot import pivot
     6666 
  -&gt; 6667         return pivot(self, index=index, columns=columns, values=values)
     6668 
     6669     _shared_docs[
  
  ~\AppData\Roaming\Python\Python38\site-packages\pandas\core\reshape\pivot.py in pivot(data, index, columns, values)
      463             index = [data[idx] for idx in index]
      464 
  --&gt; 465         data_columns = [data[col] for col in columns]
      466         index.extend(data_columns)
      467         index = MultiIndex.from_arrays(index)
  
  ~\AppData\Roaming\Python\Python38\site-packages\pandas\core\reshape\pivot.py in &lt;listcomp&gt;(.0)
      463             index = [data[idx] for idx in index]
      464 
  --&gt; 465         data_columns = [data[col] for col in columns]
      466         index.extend(data_columns)
      467         index = MultiIndex.from_arrays(index)
  
  ~\AppData\Roaming\Python\Python38\site-packages\pandas\core\frame.py in __getitem__(self, key)
     2897             if self.columns.nlevels &gt; 1:
     2898                 return self._getitem_multilevel(key)
  -&gt; 2899             indexer = self.columns.get_loc(key)
     2900             if is_integer(indexer):
     2901                 indexer = [indexer]
  
  ~\AppData\Roaming\Python\Python38\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
     2889                 return self._engine.get_loc(casted_key)
     2890             except KeyError as err:
  -&gt; 2891                 raise KeyError(key) from err
     2892 
     2893         if tolerance is not None:
  
  KeyError: 0
  </code></pre>