Example 1: join on column pandas
df1.merge(df2,on='columnName',how='left')
Example 2: combining 2 dataframes pandas
df_3 = pd.concat([df_1, df_2])
Example 3: Joins with another DataFrame
df.join(df2, df.name == df2.name, 'outer').select(
df.name, df2.height).collect()
df.join(df2, 'name', 'outer').select('name', 'height').collect()
cond = [df.name == df3.name, df.age == df3.age]
df.join(df3, cond, 'outer').select(df.name, df3.age).collect()
df.join(df2, 'name').select(df.name, df2.height).collect()
df.join(df4, ['name', 'age']).select(df.name, df.age).collect()
Example 4: merge two df
bigdata = pd.concat([data1, data2], ignore_index=True, sort=False)
Example 5: join in pandas
import pandas as pd
clients = {'Client_ID': [111,222,333,444,555],
'Client_Name': ['Jon Snow','Maria Green', 'Bill Jones','Rick Lee','Pamela Lopez']
}
df1 = pd.DataFrame(clients, columns= ['Client_ID','Client_Name'])
countries = {'Client_ID': [111,222,333,444,777],
'Client_Country': ['UK','Canada','Spain','China','Brazil']
}
df2 = pd.DataFrame(countries, columns= ['Client_ID', 'Client_Country'])
Inner_Join = pd.merge(df1, df2, how='inner', on=['Client_ID', 'Client_ID'])
print(Inner_Join)
Example 6: python dataframe left join
>>> left.merge(right, on='user_id', how='left')