Pandas Merge two DataFrames without some columns Pandas Merge two DataFrames without some columns pandas pandas

Pandas Merge two DataFrames without some columns


You can first access the relevant dataframe columns via their labels (e.g. df_a[['EntityNum', 'foo']] and then join those.

df_a[['EntityNum', 'foo']].merge(df_b[['EntityNum', 'a_col']], on='EntityNum', how='left')

Note that the default behavior for merge is to do an inner join.


Note how in SQL, you first do the join and then select the columns that you want. In the same spirit, you can do a full join in Pandas and then select the wanted columns.

Alternatively, do a full join and del the columns you do not want.

Finally, you can first select the columns that you ant and then do the join.