I'm having problems trying to use a variable containing my expression in the selectExpr of a dataframe.
So I have my variable as:
expression = '"substr(value,1,1) as qffffffffbf3ef0cf","substr(value,2,1) as q6a0aaf20"'
And trying to use this on the dataframe as:
ascii_df.selectExpr(expression).show(1)
However I keep getting a mismatched input error. If I put the expression in directly as follows it works:
ascii_df.selectExpr("substr(value,1,1) as qffffffffbf3ef0cf","substr(value,2,1) as q6a0aaf20").show(1)
Is there a way of doing this in PySpark?