I need to do group by smoothening of sales percentage values which could be erratic due to out of stock situations. I have my data in a Pandas dataframe. Here is the code I am trying:
from scipy.interpolate import UnivariateSpline
s = base_data1.groupby(['MDSE_ITEM_I','CO_LOC_I'])\
.transform(lambda x: UnivariateSpline(np.arange(x.count()), x['PCT_TILL_DATE'].value, s=x.count()))
Here I am passing np.arange(x.count())
as x
monotonically increasing array and passing values of Pandas series x['PCT_TILL_DATE'].value
as y
with good enough smoothing factor s
as x.count()
. However I am getting error:
KeyError: ('PCT_TILL_DATE', u'occurred at index GREG_D')
What I am missing here?