简体   繁体   English

python中的lambda解释

[英]Explanation for lambda in python

I'm a newbie in Data Analytics. 我是数据分析的新手。 Can someone please explain the use of the lambda for counting x using lambda function. 有人可以解释使用lambda函数计算x时使用lambda吗。

specific_lambda=lambda x: set(['Adventure','Fantasy', 'Comedy','Drama']).issubset(x)
comic_movies=df[df.geners_arr.map(specific_lambda)]
comic_movies

count_lambda=lambda x: len(x)

df['Genre_count for Movie']=df.geners_arr.apply(count_lambda)
df.head(3)

Lambda functions are anonymous functions. Lambda函数是匿名函数。 The following two are equivalent: 以下两个是等效的:

def count_lambda(x):
    return len(x)

is the same as 是相同的

count_lambda = lambda x: len(x)

See also https://docs.python.org/3/tutorial/controlflow.html#lambda-expressions 另请参见https://docs.python.org/3/tutorial/controlflow.html#lambda-expressions

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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