加入两个pyspark数据帧以从第一个df中选择所有列,从第二个df中选择一些列

问题描述 投票:1回答:1

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

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

我真的不明白那行代码怎么了?谢谢。

python-3.x apache-spark pyspark pyspark-sql
1个回答
1
投票

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'])
© www.soinside.com 2019 - 2024. All rights reserved.