'Pandas groupby and apply function on group
On a pandas df of the below info
STOCK YR MONTH DAY PRICE
AAA 2022 1 1 10
AAA 2022 1 2 11
AAA 2022 1 3 10
AAA 2022 1 4 15
AAA 2022 1 5 10
BBB 2022 1 1 5
BBB 2022 1 2 10
BBB 2022 2 1 10
BBB 2022 2 2 15
I am trying to group by STOCK and applying the following function
def next_pred(currents):
model = SimpleExpSmoothing(currents['PRICE'])
model_fit=model.fit()
next_price=model_fit.predict()
return (int(np.floor(next_price)))
I am using the following line of code:
future_price =df.groupby(['STOCK']).apply(lambda x: next_pred(x)).reset_index()
However, I am getting the below error:
IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed
A print of the df['PRICE'] from within the function, prints the data properly. Any suggestions on what might be causing the indexing error?
Thanks!
But I am not sure
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
