returning an error when writign gt() in the lambda function in pandas

Viewed 20

I'm using gt() and lt() pandas functions in lambda. But it's returning the error. Below is the code

df = pd.DataFrame({'PRODUCT_NAME': ['HYDT300ML', 'HYDT300ML', 'HYDT300ML', 'HYDT300ML', 'HYDT300ML'],
                   'WEEK_NUMBER': [1, 1, 2, 1, 3],
                   'PROMO_DEPTH': [0, 0.3, 0.3, 0.4, 0.3],
                   'SUM_PROD_SELL_QTY': [6, 29, 10, 20, 45]})

df['diff'] = df.groupby(['PRODUCT_NAME', 'PROMO_DEPTH'])['SUM_PROD_SELL_QTY'].diff()
df['diff'] = df['diff'].fillna(0)
df['uplift'] = df['diff'].apply(lambda x: x if x &gt() 0 else 0)
df['downlift'] = df['diff'].apply(lambda x: x if x &lt() 0 else 0)
df['uplift_percent'] = df['uplift'] / df['SUM_PROD_SELL_QTY']
df['downlift_percent'] = df['downlift'] / df['SUM_PROD_SELL_QTY']
df['total_uplift_percent'] = df.groupby(['PRODUCT_NAME', 'PROMO_DEPTH'])['uplift_percent'].cumsum()
df['total_downlift_percent'] = df.groupby(['PRODUCT_NAME', 'PROMO_DEPTH'])['downlift_percent'].cumsum()

Below is the error for the above code

File "<ipython-input-37-8aa81d56c14b>", line 8
    df['uplift'] = df['diff'].apply(lambda x: x if x &gt() 0 else 0)
                                                           ^
SyntaxError: invalid syntax

Can anyone help me resolving this error? I'm unable to resolve this issue.

0 Answers
Related