Reputation: 175
I have 2 CSV files like so:
sheet1.csv only contains headers
Account_1 Amount_1 Currency_1 Country_1 Date_1
sheet2.csv contains headers and data
Account Currency Amount Date Country
1 GBP 117.89 20/02/2021 UK
2 GBP 129.39 15/02/2021 UK
How can I use pandas to map the data from sheet2 to sheet1 as I want the data to have the new column names in the same exact order.
Upvotes: 1
Views: 87
Reputation: 1144
First arrange the columns on sheet2 by order as sheet1
sheet2 = sheet2[["Account", "Amount", "Currency", "Country", "Date"]]
This will rearrange sheet2 columns and then
sheet2.columns = sheet1.columns
Final output of sheet2.head()
will be
Account_1 Amount_1 Currency_1 Country_1 Date_1 1 117.89 GBP UK 20/02/2021 2 129.39 GBP UK 15/02/2021
Upvotes: 1