How can I insert a Series into a DataFrame row?
<p>I have a DataFrame like this:</p>

<pre><code>import pandas as pd
import numpy as np
df = pd.DataFrame(columns=['a','b','c','d'], index=['x','y','z'])
df
     a    b    c    d
x  NaN  NaN  NaN  NaN
y  NaN  NaN  NaN  NaN
z  NaN  NaN  NaN  NaN
</code></pre>

<p>I also have a Series like this</p>

<pre><code>s = pd.Series(np.random.randn(3), index=['b', 'c', 'd'])
s
b   -0.738283
c   -0.649760
d   -0.777346 
dtype: float64
</code></pre>

<p>I want to insert the Series into a row of the DataFrame, for example the 1th row, resulting the final DataFrame:</p>

<pre><code>     a       b          c         d
x  NaN      NaN        NaN       NaN
y  NaN  -0.738283  -0.649760  -0.777346
z  NaN      NaN        NaN       NaN
</code></pre>

<p>How can I do it? thanks in advance ;)</p>

<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.iloc.html" rel="nofollow"><code>iloc</code></a> if need select <code>index</code> of <code>df</code> by position:</p>

<pre><code>#select second row (python counts from 0)
df.iloc[1] = s
print (df)
     a        b         c       d
x  NaN      NaN       NaN     NaN
y  NaN  1.71523  0.269975 -1.3663
z  NaN      NaN       NaN     NaN
</code></pre>

<p>Or <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.ix.html" rel="nofollow"><code>ix</code></a> (<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.loc.html" rel="nofollow"><code>loc</code></a>) if need select by label:</p>

<pre><code>df.ix['y'] = s
df.loc['z'] = s
print (df)

     a         b         c         d
x  NaN       NaN       NaN       NaN
y  NaN  0.619316  0.917374 -0.559769
z  NaN  0.619316  0.917374 -0.559769
</code></pre>

python pandas numpy dataframe