此功能:
from pyspark.sql import functions as F
lg = F.log(5.2)
来自http://spark.apache.org/docs/latest/api/python/pyspark.sql.html
返回:
Py4JError: An error occurred while calling z:org.apache.spark.sql.functions.col. Trace:
py4j.Py4JException: Method col([class java.lang.Double]) does not exist
at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:318)
at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:339)
at py4j.Gateway.invoke(Gateway.java:274)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:214)
at java.lang.Thread.run(Thread.java:745)
文档指出在数据框中使用该函数:
>>> df.select(log(10.0, df.age).alias('ten')).rdd.map(lambda l: str(l.ten)[:7]).collect()
['0.30102', '0.69897']
>>> df.select(log(df.age).alias('e')).rdd.map(lambda l: str(l.e)[:7]).collect()
['0.69314', '1.60943']
是否还应该能够在值上独立使用log
函数?
答案 0 :(得分:2)
pyspark.sql
中的函数应该用于dataframe列。这些函数需要将列作为参数传递。因此,它正在寻找一个具有您传递的名称的列对象(在本例中为5.2),因此错误。
对于您应该使用log
代替
math.log