using python ewm() in a prepare recipe

Options
Lesage
Lesage Registered Posts: 3

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 ?

Tagged:

Answers

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 1,708 Neuron
    Options

    Hi, what error do you get?

  • Lesage
    Lesage Registered Posts: 3
    Options

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

  • Catalina
    Catalina Dataiker, Dataiku DSS Core Designer, Registered Posts: 135 Dataiker
    Options

    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?

  • Lesage
    Lesage Registered Posts: 3
    Options

    it s a csv file

    i d like to transform some column to calculate ewm

    how I can do that ?

Setup Info
    Tags
      Help me…