我尝试导入两个函数,如下所示,但出现错误
from pyspark.sql.functions import regexp_replace, col
df1 = sales.alias('a').join(customer.alias('b'),col('b.ID') == col('a.ID'))\
.select([col('a.'+xx) for xx in sales.columns] + col('b.others')
TypeError: 'str' object is not callable
我真的不明白那行代码怎么了?谢谢。
答案 0 :(得分:1)
PySpark选择函数仅需要字符串列名,而无需将列对象作为数组发送。所以您只需要这样做
from pyspark.sql.functions import regexp_replace, col
df1 = sales.alias('a').join(customer.alias('b'),col('b.ID') == col('a.ID'))\
.select(sales.columns + ['others'])