将两个 pyspark 数据帧连接到 select 第一个 df 的所有列和第二个 df 的一些列

Join two pyspark dataframes to select all the columns from the first df and some columns from the second df

我尝试导入两个函数,如下所示,但出现错误

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

我真的不明白那行代码有什么问题?谢谢

PySpark select 函数仅需要字符串列名称,无需将列对象作为数组发送。所以你可能只需要这样做

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'])