0

I'm trying to convert this Python lambda function to an if-else statement so that I can add other arguments onto it. Could someone explain how this Lambda would look like if converted to an if-esle statement?

df['type'] = df[FEATURE_NAME].map(lambda column_name: 'property' if is_categorical(column_name) else 'metric')
7
  • 1
    it current is an if-else statement Commented Oct 10, 2019 at 20:41
  • @PaulH No, it's a conditional expression. Commented Oct 10, 2019 at 20:42
  • potato pah-tah-toe Commented Oct 10, 2019 at 20:47
  • @PaulH no it isn't, it's a conditional expression. And that is an important distinction, since you cannot put complex statements in lambda functions, they accept only expressions. Commented Oct 10, 2019 at 21:15
  • @juanpa.arrivillaga see my response to the other person who said nearly the exact same thing Commented Oct 10, 2019 at 21:16

1 Answer 1

1

Is this the answer you're looking for?

def foo(column_name): 
    if is_categorical(column_name):
        return 'property'
    else:
        return 'metric'     

df['type'] = df[FEATURE_NAME].map(foo)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.