python pandas elegant dataframe access rows 2:end
<p>I have a dataframe, <code>dF = pd.DataFrame(X)</code> where X is a numpy array of doubles. I want to remove the last row from the dataframe. I know for the first row I can do something like this <code>dF.ix[1:]</code>. I want to do something similar for the last row. I know in matlab you could do something like this <code>dF[1:end-1]</code>. What is a good and readable way to do this with pandas?</p>

<p>The end goal is to achieve this:
first matrix</p>

<pre><code>1 2 3
4 5 6
7 8 9
</code></pre>

<p>second matrix</p>

<pre><code>a b c
d e f
g h i
</code></pre>

<p>now get rid of first row of first matrix and last row of second matrix and horizontally concatentate them like so:</p>

<pre><code>4 5 6 a b c
7 8 9 d e f
</code></pre>

<p>done. In matlab a = firstMatrix. b = secondMatrix. <code>c = [a[2:end,:] b[1:end-1,:]]</code> where c is the resulting matrix.</p>

<p>you can do it this way:</p>

<pre><code>In [129]: df1
Out[129]:
   c1  c2  c3
0   1   2   3
1   4   5   6
2   7   8   9

In [130]: df2
Out[130]:
  c1 c2 c3
0  a  b  c
1  d  e  f
2  g  h  i

In [131]: df1.iloc[1:].reset_index(drop=1).join(df2.iloc[:-1].reset_index(drop=1), rsuffix='_2')
Out[131]:
   c1  c2  c3 c1_2 c2_2 c3_2
0   4   5   6    a    b    c
1   7   8   9    d    e    f
</code></pre>

<p>Or a pure NumPy solution:</p>

<pre><code>In [132]: a1 = df1.values

In [133]: a1
Out[133]:
array([[1, 2, 3],
       [4, 5, 6],
       [7, 8, 9]], dtype=int64)

In [134]: a2 = df2.values

In [135]: a2
Out[135]:
array([['a', 'b', 'c'],
       ['d', 'e', 'f'],
       ['g', 'h', 'i']], dtype=object)

In [136]: a1[1:]
Out[136]:
array([[4, 5, 6],
       [7, 8, 9]], dtype=int64)

In [137]: a2[:-1]
Out[137]:
array([['a', 'b', 'c'],
       ['d', 'e', 'f']], dtype=object)

In [138]: np.concatenate((a1[1:], a2[:-1]), axis=1)
Out[138]:
array([[4, 5, 6, 'a', 'b', 'c'],
       [7, 8, 9, 'd', 'e', 'f']], dtype=object)
</code></pre>

python matlab pandas numpy