using python ewm() in a prepare recipe

Lesage
Level 2
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 ?

 

0 Kudos
4 Replies
Turribeach

Hi, what error do you get?

0 Kudos
Lesage
Level 2
Author

 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'])

 

 

0 Kudos
CatalinaS
Dataiker

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?

0 Kudos
Lesage
Level 2
Author

it s a csv file

i d like to transform some column to calculate ewm

how I can do that ?

 

 

0 Kudos