df join pandas code example
Example 1: union df pandas
pd.concat([df1, df2])
Example 2: join on column pandas
df1.merge(df2,on='columnName',how='left')
Example 3: pandas left join
df.merge(df2, left_on = "doc_id", right_on = "doc_num", how = "left")
Example 4: 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 5: join tables pandas
In [88]: result = left.join(right, how='inner')