简体   繁体   中英

How to write lambda as def function?

How do I write the below lambda function as a def function?

df['hourly'] = df['Salary Estimate'].apply(lambda x: 1 if 'per hour' in x.lower() else 0)
def fun(x):
   return 1 if 'per hour' in x.lower() else 0

then

df['hourly'] = df['Salary Estimate'].apply(fun)
def my_super_fun(x):
    return 1 if 'per hour' in x.lower() else 0
df['hourly'] = df['Salary Estimate'].apply(my_super_fun)

You can pass any one-argument function to apply function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM