1# df1 as main df and use the feild from df2 and map it into df1
2
3df1.merge(df2,on='columnName',how='left')
1# Joins with another DataFrame
2
3df.join(df2, df.name == df2.name, 'outer').select(
4 df.name, df2.height).collect()
5# [Row(name=None, height=80), Row(name=u'Bob', height=85), Row(
6# name=u'Alice', height=None)]
7
8df.join(df2, 'name', 'outer').select('name', 'height').collect()
9# [Row(name=u'Tom', height=80), Row(name=u'Bob', height=85), Row(
10# name=u'Alice', height=None)]
11
12cond = [df.name == df3.name, df.age == df3.age]
13df.join(df3, cond, 'outer').select(df.name, df3.age).collect()
14# [Row(name=u'Alice', age=2), Row(name=u'Bob', age=5)]
15
16df.join(df2, 'name').select(df.name, df2.height).collect()
17# Row(name=u'Bob', height=85)]
18
19df.join(df4, ['name', 'age']).select(df.name, df.age).collect()
20# [Row(name=u'Bob', age=5)]
1>>> df.join(other.set_index('key'), on='key')
2 key A B
30 K0 A0 B0
41 K1 A1 B1
52 K2 A2 B2
63 K3 A3 NaN
74 K4 A4 NaN
85 K5 A5 NaN
9