title: Adding a vector to each row in pandas
body: <p>I have a pandas dataframe and a function that returns a vector, I want to "add" those vectors to my frame like followed: </p>
  
  <pre><code>for i in range(len(Training_Frame)):
      Training_Frame.insert(i,'ONEcoded',onehot_processing(int(float(Training_Frame.iloc[i,-1])),numberOFclasses))
  </code></pre>
  
  <p>as an example, say the o<code>onehot_processing</code> function returns <code>[0,0,0,1,0]</code> each time. the <code>Training_Frame</code> first rows looks like:  </p>
  
  <pre><code>row0 [1,2,3,4,5]
  row1 [2,3,4,5,3]
  .............
  </code></pre>
  
  <p>how can I add the returned vector as followed:</p>
  
  <pre><code>row0 [1,2,3,4,5,0,0,0,1,0]
  row1 [2,3,4,5,3,0,0,0,1,0]
  .............
  </code></pre>
  
  <p>The error message I get when I try to run the loop is :</p>
  
  <pre><code>    ---------------------------------------------------------------------------
  ValueError                                Traceback (most recent call last)
  &lt;ipython-input-9-1a385098ae56&gt; in &lt;module&gt;()
        1 for i in range(len(Training_Frame)):
  ----&gt; 2     Training_Frame.insert(i,'ONEcoded',onehot_processing(int(float(Training_Frame.iloc[i,-1])),numberOFclasses))
  
  c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\pandas\core\frame.py in insert(self, loc, column, value, allow_duplicates)
     2507         """
     2508         self._ensure_valid_index(value)
  -&gt; 2509         value = self._sanitize_column(column, value, broadcast=False)
     2510         self._data.insert(loc, column, value,
     2511                           allow_duplicates=allow_duplicates)
  
  c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\pandas\core\frame.py in _sanitize_column(self, key, value, broadcast)
     2654 
     2655             # turn me into an ndarray
  -&gt; 2656             value = _sanitize_index(value, self.index, copy=False)
     2657             if not isinstance(value, (np.ndarray, Index)):
     2658                 if isinstance(value, list) and len(value) &gt; 0:
  
  c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\pandas\core\series.py in _sanitize_index(data, index, copy)
     2798 
     2799     if len(data) != len(index):
  -&gt; 2800         raise ValueError('Length of values does not match length of ' 'index')
     2801 
     2802     if isinstance(data, PeriodIndex):
  
  ValueError: Length of values does not match length of index
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <pre><code>#Function to generate a onehot coded vector based on
  #number of class &amp; the given class ID
  def onehot_processing(classID, numberOFclasses):
      one_hot_vector=np.zeros(numberOFclasses)
      one_hot_vector[classID-1] = 1
      return one_hot_vector
  </code></pre>
  
  <p>ClassID is saved in the last column of the dataframe </p>