merge two dataframes based on column
df_outer = pd.merge(df1, df2, on='id', how='outer') #here id is common column
df_outer
                                
                            merge two dataframes based on column
df_outer = pd.merge(df1, df2, on='id', how='outer') #here id is common column
df_outer
                                
                            combine two dataframe in pandas
# Stack the DataFrames on top of each other
vertical_stack = pd.concat([survey_sub, survey_sub_last10], axis=0)
# Place the DataFrames side by side
horizontal_stack = pd.concat([survey_sub, survey_sub_last10], axis=1)
                                
                            combine dataframes with two matching columns
merged_df = DF2.merge(DF1, how = 'inner', on = ['date', 'hours'])
                                
                            pandas create a new column based on condition of two columns
conditions = [
    df['gender'].eq('male') & df['pet1'].eq(df['pet2']),
    df['gender'].eq('female') & df['pet1'].isin(['cat', 'dog'])
]
choices = [5,5]
df['points'] = np.select(conditions, choices, default=0)
print(df)
     gender      pet1      pet2  points
0      male       dog       dog       5
1      male       cat       cat       5
2      male       dog       cat       0
3    female       cat  squirrel       5
4    female       dog       dog       5
5    female  squirrel       cat       0
6  squirrel       dog       cat       0
                                
                            pandas merge two columns from different dataframes
#suppose you have two dataframes df1 and df2, and 
#you need to merge them along the column id
df_merge_col = pd.merge(df1, df2, on='id')
                                
                            Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us