To merge data from multiple Excel files, you can use different methods depending on the tools you are comfortable with. Below are methods for merging Excel files using Microsoft Excel, Python (pandas), and Power Query.
1. Using Microsoft Excel
If you have a few files and don’t want to write code, Excel itself can be a good tool to merge the data:
Method 1: Copy and Paste
-
Open all the Excel files you want to merge.
-
Copy the data from one file and paste it into the other file where you want to consolidate everything.
-
If the files have the same structure, paste them below the existing data.
Method 2: Power Query
Power Query allows you to load data from multiple files and merge them automatically. Here’s how you can do that:
-
Open Excel and go to the Data tab.
-
Click on Get Data, then choose From File → From Folder.
-
Browse to the folder where the files are located and select OK.
-
A dialog will appear showing all the files in the folder. Click on Combine and then Combine & Load.
-
Power Query will automatically combine the files. You can then transform or clean the data as needed before loading it into a new sheet.
2. Using Python (pandas)
For more control and automation, especially when working with large datasets or needing to repeat the process, Python with the pandas
library is an efficient option.
Steps:
-
Install pandas (if you don’t have it installed yet):
-
Use pandas to merge Excel files:
This script will:
-
Search for all Excel files (
.xlsx
) in the specified folder. -
Read each file into a pandas DataFrame.
-
Merge them into a single DataFrame.
-
Save the merged data into a new Excel file called
merged_output.xlsx
.
-
3. Using Power BI (for more advanced users)
Power BI can be another tool for merging Excel files, especially if you need to create reports or visualize the data afterward.
-
Open Power BI Desktop.
-
Click on Get Data > Folder.
-
Choose the folder where the Excel files are stored.
-
Power BI will load a list of all files in the folder. You can then select Combine to merge them.
-
Once merged, you can transform the data using Power Query and load it into the report view.
4. Using Google Sheets
If you prefer cloud-based solutions:
-
Upload all your Excel files to Google Drive and convert them into Google Sheets.
-
Use the IMPORTRANGE function to pull data from different sheets.
-
Combine data from different sheets into a master sheet by referencing all other sheets with
IMPORTRANGE
or by using QUERY for more advanced merging.
Choose the method based on the volume of data, your familiarity with the tools, and the complexity of the merging process. For automation and larger datasets, Python with pandas is usually the best choice. If you prefer a GUI, Power Query in Excel is very efficient for merging multiple files.
Leave a Reply