Extract first and last row of a dataframe in pandas
<p><strong>How can I extract the first and last rows of a given dataframe as a new dataframe in pandas?</strong></p>

<p>I've tried to use <code>iloc</code> to select the desired rows and then <code>concat</code> as in:</p>

<pre><code>df=pd.DataFrame({'a':range(1,5), 'b':['a','b','c','d']})
pd.concat([df.iloc[0,:], df.iloc[-1,:]])
</code></pre>

<p>but this does not produce a pandas dataframe:</p>

<pre><code>a    1
b    a
a    4
b    d
dtype: object
</code></pre>