Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas Copy columns from one data frame to another with different name

I have to copy columns from one DataFrame A to another DataFrame B. The column names in A and B do not match.

What is the best way to do it? There are several columns like this. Do I need to write for each column like B["SO"] = A["Sales Order"] etc.

like image 863
user11334842 Avatar asked Sep 17 '25 16:09

user11334842


1 Answers

i would use pd.concat

combined_df = pd.concat([df1, df2[['column_a', 'column_b']]], axis=1)

also gives you the power to concat different size dateframes , outer join etc.

like image 193
masasa Avatar answered Sep 19 '25 04:09

masasa