我是相对较新的Spark用户,在导入pyspark函数后使用Python内置的round()函数时遇到了问题。这似乎与我如何导入pyspark函数有关,但我不确定其中的区别,也不知道为什么一种方式会引起问题而另一种方式不会。
期望的行为:
期望的行为:
import pyspark.sql.functions
print(round(3.14159265359,2))
>>> 3.14
意外行为:
from pyspark.sql.functions import *
print(round(3.14159265359,2))
>>> ERROR
AttributeError Traceback (most recent call last)
<ipython-input-1-50155ca4fa82> in <module>()
1 from pyspark.sql.functions import *
----> 2 print(round(3.1454848383,2))
/opt/spark/python/pyspark/sql/functions.py in round(col, scale)
503 """
504 sc = SparkContext._active_spark_context
--> 505 return Column(sc._jvm.functions.round(_to_java_column(col), scale))
506
507
AttributeError: 'NoneType' object has no attribute '_jvm'
import *
以其他方式工作吗?请阅读“为什么import *
不好?”(https://dev59.com/JXE95IYBdhLWcg3wQ7uc)。 - pault