# Note: You can use .join to perform joins between multiple dataframes if they have indexes
df_all = df1.join([df2, df3], how="inner")
# Inner Join
merged_df = left_df.merge(right_df, on=['col1','col2'],
validate=None, # Validate used to verify 1:1, 1:N relationship
suffixes=('_left','_right'), how='inner')
# Left Join
merged_df = left_df.merge(right_df, on=['col1','col2'],
suffixes=('_left','_right'), how='left')
# Left Join on nearest value
merged_df = pd.merge_asof(left_df, right_df, on=['date'],
suffixes=('_left','_right'),
direction='nearest')
# Right Join
merged_df = left_df.merge(right_df, on=['col1','col2'],
suffixes=('_left','_right'), how='right')
# Outer Join
merged_df = left_df.merge(right_df, on=['col1','col2'],
suffixes=('_left','_right'), how='outer')
# Alternative outer join
merged_df = pd.merge_ordered(left_df, right_df, on='date',
suffixes=('_left','_right'),
fill_method='ffill')
# Alternative approach
merged_df = left_df.merge(right_df, left_on='left_col', right_on='right_col',
left_index=True, right_index=True, # if they are index
suffixes=('_left','_right'), how='outer')
# Semi Join
inner_join_df = left_df.merge(right_df, on='id')
semi_join_df = left_df[left_df['id'].isin(inner_join_df['id'])]
# Anti Join
inner_join_df = left_df.merge(right_df, on='id')
anti_join_df = left_df[~left_df['id'].isin(inner_join_df['id'])]
# Note : There are other keyword arguments in merge method for more flexibility
merged_df = left_df.merge(right_df, how='outer', # This will be an outer join
left_index=True, # The left_df's index is used for joining
right_on='id', # The right_df's normal column is used for joining
suffixes=('_left', '_right'), # Duplicate columns from both dataframes will be suffixed
indicator=True, # A new column will tell which dataframe the value comes from
validate='1:m', # Validate whether left to right table joining has one-to-many relationship
sort="id") # The final merged dataframe will be sorted by this column
# Joining on exact value of Date column
merged_df = pd.merge_ordered(left_df, right_df, on="date_col",
suffixes=['_left', '_right'], fill_method='ffill')
# Joining on approximate value of Date column
merged_df = pd.merge_asof(left_df, right_df, on="date_col",
suffixes=['_left', '_right'], direction='nearest')