split data frame based on integer index

pandas

Solution

Use slice:

In [11]: s = pd.Series([1,2,3,4])

In [12]: s.iloc[::2]  # even
Out[12]:
0    1
2    3
dtype: int64

In [13]: s.iloc[1::2]  # odd
Out[13]:
1    2
3    4
dtype: int64

Problem

In pandas how do I split Series/dataframe into two Series/DataFrames where odd rows in one Series, even rows in different? Right now I am using ``` rng = range(0, n, 2) odd_rows = df.iloc[rng] ``` This is pretty slow.

Original source