Skip to content
Advertisement

Append only matching columns to dataframe

I have a sort of ‘master’ dataframe that I’d like to append only matching columns from another dataframe to

JavaScript

The problem is that when I use df.append(), It also appends the unmatched columns to df.

JavaScript

But my desired output is to drop columns D and E since they are not a part of the original dataframe? Perhaps I need to use pd.concat? I don’t think I can use pd.merge since I don’t have anything unique to merge on.

Advertisement

Answer

Using concat join='inner

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement