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)
and create_ohlc is the following:
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
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
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?