[SOLVED] I am getting an error while i am running a function in pandas dataframe.I am getting invalid syntax for the first line of the function

Issue

def revised_price(engine-location,price):
if engine-location==front:
updated_price== price
else:
updated_price== 2*price

return new_profit

df[‘updated_price’] = df.apply(lambda x: revised_price(x[‘engine-location’], x[‘price’]),axis=1)

Please find the error that i am getting
File "", line 1
def revised_price(engine-location,’price):
^
SyntaxError: invalid syntax

Solution

You didn’t follow naming convention here

You can’t name inside a function like engine-location , instead rename it to engine_location, and also instead of

updated_price == price

try

updated_price = price

and instead of

updated_price == 2*price

use

updated_price = 2*price

Answered By – user15395644

Answer Checked By – Mary Flores (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *