using python ewm() in a prepare recipe
HI
I have a dataset with a column a and I d like to compute the ewm using python code
def process(row):
row['a_ewm']=row['a'].ewm(span=30).mean()
return len(row['a_ewm'])
but it s mot working
can someone help me ?
Answers
-
Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,160 Neuron
Hi, what error do you get?
-
Error while running a script step
Python runtime error/ <type 'exceptions.AttributeError'> : AttributeError("'unicode' object has no attribute 'ewm'",). Traceback (most recent call last): File "<string>", line 2, in process , caused by: PyException: AttributeError: 'unicode' object has no attribute 'ewm'
def process(row):
row['a_ewm']=row['a'].ewm(span=30).mean()
return len(row['a_ewm']) -
Hi @Lesage
,It seems that ewm() is a function in Pandas library for exponentially weighted (EW) calculations.
https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.ewm.html
If you want to use this you need to create a Pandas Dataframe object and then call this function ewm().
This seems to require a series of data so if you want to calculate exponentially weighted mean of a column, row formula doesn't seem suitable for this because you will have access only to one row at a time.
How does your input data look like?
-
it s a csv file
i d like to transform some column to calculate ewm
how I can do that ?