title: Python pandas: fill a dataframe row by row
body: <p>The simple task of adding a row to a <code>pandas.DataFrame</code> object seems to be hard to accomplish. There are 3 stackoverflow questions relating to this, none of which give a working answer.</p>
  
  <p>Here is what I'm trying to do. I have a DataFrame of which I already know the shape as well as the names of the rows and columns.</p>
  
  <pre><code>&gt;&gt;&gt; df = pandas.DataFrame(columns=['a','b','c','d'], index=['x','y','z'])
  &gt;&gt;&gt; df
       a    b    c    d
  x  NaN  NaN  NaN  NaN
  y  NaN  NaN  NaN  NaN
  z  NaN  NaN  NaN  NaN
  </code></pre>
  
  <p>Now, I have a function to compute the values of the rows iteratively. How can I fill in one of the rows with either a dictionary or a <code>pandas.Series</code> ? Here are various attempts that have failed:</p>
  
  <pre><code>&gt;&gt;&gt; y = {'a':1, 'b':5, 'c':2, 'd':3} 
  &gt;&gt;&gt; df['y'] = y
  AssertionError: Length of values does not match length of index
  </code></pre>
  
  <p>Apparently it tried to add a column instead of a row.</p>
  
  <pre><code>&gt;&gt;&gt; y = {'a':1, 'b':5, 'c':2, 'd':3} 
  &gt;&gt;&gt; df.join(y)
  AttributeError: 'builtin_function_or_method' object has no attribute 'is_unique'
  </code></pre>
  
  <p>Very uninformative error message.</p>
  
  <pre><code>&gt;&gt;&gt; y = {'a':1, 'b':5, 'c':2, 'd':3} 
  &gt;&gt;&gt; df.set_value(index='y', value=y)
  TypeError: set_value() takes exactly 4 arguments (3 given)
  </code></pre>
  
  <p>Apparently that is only for setting individual values in the dataframe.</p>
  
  <pre><code>&gt;&gt;&gt; y = {'a':1, 'b':5, 'c':2, 'd':3} 
  &gt;&gt;&gt; df.append(y)
  Exception: Can only append a Series if ignore_index=True
  </code></pre>
  
  <p>Well, I don't want to ignore the index, otherwise here is the result:</p>
  
  <pre><code>&gt;&gt;&gt; df.append(y, ignore_index=True)
       a    b    c    d
  0  NaN  NaN  NaN  NaN
  1  NaN  NaN  NaN  NaN
  2  NaN  NaN  NaN  NaN
  3    1    5    2    3
  </code></pre>
  
  <p>It did align the column names with the values, but lost the row labels.</p>
  
  <pre><code>&gt;&gt;&gt; y = {'a':1, 'b':5, 'c':2, 'd':3} 
  &gt;&gt;&gt; df.ix['y'] = y
  &gt;&gt;&gt; df
                                    a                                 b  \
  x                               NaN                               NaN
  y  {'a': 1, 'c': 2, 'b': 5, 'd': 3}  {'a': 1, 'c': 2, 'b': 5, 'd': 3}
  z                               NaN                               NaN
  
                                    c                                 d
  x                               NaN                               NaN
  y  {'a': 1, 'c': 2, 'b': 5, 'd': 3}  {'a': 1, 'c': 2, 'b': 5, 'd': 3}
  z                               NaN                               NaN
  </code></pre>
  
  <p>That also failed miserably.</p>
  
  <p>So how do you do it ?</p>