简单的问题,横向连接两个df,如下图所示。
pyspark中没有类似padas中的pd.concat([df1,df2],axis='columns')用以连接两个df,中文搜索半天都是些文不对题的答案,还是得科学搜索,墙外出真知。特此记录解决办法:
from pyspark.sql.functions import monotonically_increasing_id as mi
id=mi()
df1 = df1.withColumn("match_id", id)
cont_data = cont_data.withColumn("match_id", id)
cont_data = cont_data.join(df1,df1.match_id==cont_data.match_id, 'inner').drop(df1.match_id)
pyspark只能用join方法横向连接,因此需要构造一个临时的相同列使用。构造完之后丢弃即可。