Python Pandas, slice rows from group in .groupby().apply()
<p>I have the following code setup that calls and groupBy and apply on a Python Pandas DataFrame.</p>

<p>The bizarre thing is I am unable to slice the grouped data by row (like <code>df.loc[2:5]</code>) without it completely screwing the output (as shown in the debug), how can you drop rows and get this to give the desired output? </p>

<p>Any help would be massively appreciated, I'm running this on a bigger example with more complicated functions, but have pinpointed the issues to the row slicing!</p>

<p>Code:</p>

<pre><code>import pandas as pd
df = pd.DataFrame({'one' : ['AAL', 'AAL', 'AAPL', 'AAPL'], 'two' : [1, 2, 3, 4]})

def net_func(df):
    df_res = daily_func(df, True)
    df_res_valid = daily_func(df, False)
    df_merge = pd.merge(df_res, df_res_valid)
    return df_merge

def daily_func(df, bool_param):

#     df.drop(df.head(1).index, inplace=True)
#     df = df[1:1]
#     df.iloc[1:1,:]
#     df.loc[1:1,:]


    if bool_param:
        df['daily'+str(bool_param)] = 1
    else:
        df['daily'+str(bool_param)] = 0    
    return df

print df.groupby('one').apply(net_func)
</code></pre>

<p>Current output:</p>

<pre><code>         one  two  dailyTrue  dailyFalse
one                                     
AAL  0   AAL    1          1           0
     1   AAL    2          1           0
AAPL 0  AAPL    1          1           0
     1  AAPL    2          1           0
</code></pre>

<p>Desired output:</p>

<pre><code>         one  two  dailyTrue  dailyFalse
one                                     
AAL  1   AAL    2          1           0
AAPL 1  AAPL    2          1           0
</code></pre>

<p>Ideally, I would like to be able to slice by row for each group for example <code>df.loc[3:5]</code> - This would be perfect!</p>

<p>I've tried the commented as follows:</p>

<p>output with <code>df.drop(df.head(1).index, inplace=True)</code>:</p>

<pre><code>Empty DataFrame
Columns: [one, two, dailyTrue, dailyFalse]
Index: []
</code></pre>

<p>Update: also tried output with <code>df = df[1:1]</code>:</p>

<pre><code>Empty DataFrame
Columns: [one, two, dailyTrue, dailyFalse]
Index: []
</code></pre>

<p>Update have also tried <code>df.iloc[1:1,:]</code>:</p>

<pre><code>         one  two  dailyTrue  dailyFalse
one                                     
AAL  0   AAL    1          1           0
     1   AAL    2          1           0
AAPL 0  AAPL    1          1           0
     1  AAPL    2          1           0
</code></pre>

<p>and <code>df.loc[1:1,:]</code>:</p>

<pre><code>         one  two  dailyTrue  dailyFalse
one                                     
AAL  0   AAL    1          1           0
     1   AAL    2          1           0
AAPL 0  AAPL    1          1           0
     1  AAPL    2          1           0
</code></pre>