pyspark:在一个map函数语法错误多操作 [英] pyspark:syntax error with multiple operation in one map function
问题描述
我在我的pyspark地图功能添加额外的操作。
I am adding an additional operation in my pyspark map function.
最初的功能是:
results = input.map(lambda row:process_myData(row))
这工作正常。然后我试图增加一个额外的操作象下面这样:
which works fine. Then I tried to add an additional operation like below:
results = input.map{lambda row:
row1 = row.replace("abc","def")
process_myData(row1)}
然后,我得到了下面的语法错误:
Then I got the syntax error below:
results = input.map{lambda row:
^
SyntaxError: invalid syntax
我干了什么错在这里做什么?谢谢!
What did I do wrong here? Thank you!
推荐答案
您没看过的手动。 LAMBDA前pression是一个前pression和这样一个不能包含语句。如果你不相信,你可以跟踪启动可能的扩展:
You didn't read the manual. Lambda expression is an expression and a such cannot contain statements. If you're not convinced you can trace possible expansions starting from:
lambda_expr ::= "lambda" [parameter_list]: expression
lambda_expr_nocond ::= "lambda" [parameter_list]: expression_nocond
如果你想使用的语句,你必须使用标准功能:
If you want to use statements you have to use standard function:
def f(row):
row1 = row.replace("abc","def")
return process_myData(row1)
input.map(f)
虽然这里简单的构图就足够了:
although here a simple composition would be enough:
input.map(lambda row: process_myData(row.replace("abc","def")))
这篇关于pyspark:在一个map函数语法错误多操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!