title: Why can't I use loc to access an element on a dataframe after using apply?
body: <p>I'd like to group a dataset by an ID column that I set up.
  So I have:
  df_grouped = df_grouped.groupby(by='groupID').apply(create_ohlc)</p>
  <p>and create_ohlc is the following:</p>
  <pre><code>def create_ohlc(data):
      data['open'] = data.loc[0, 'price']
      data['high'] =data.loc[:, 'price'].max()
      data['low'] = data.loc[:, 'price'].min()
      data['close'] = data.loc[-1, 'price']
      return data
  </code></pre>
  <p>I could fix it by doing like that:
  def create_ohlc(data):
  data['open'] = data.loc[data.index[0], 'price']
  data['high'] =data.loc[:, 'price'].max()
  data['low'] = data.loc[:, 'price'].min()
  data['close'] = data.loc[data.index[-1], 'price']
  return data</p>
  <p>But I still don't understand what is going on.
  And it takes a bit of time to get it done. Is there something wrong?</p>