This Python script combines multiple CSV files from a folder into a single Excel workbook, saving each CSV as a separate sheet. Designed for small businesses or individuals needing to compile data efficiently.
- Python 3.x
- Libraries: pandas, openpyxl
Windows:
- Download from python.org
- During setup, ensure “Add Python to PATH” is checked.
macOS:
- Check if installed:
python3 --version - If not, install via Homebrew:
brew install python
Windows:
Open Command Prompt and run:
pip install pandas openpyxl
macOS:
Open Terminal and run:
pip3 install pandas openpyxl
- Place your CSV files into a folder (e.g.
data/). - In the script file, update these variables to your folder and desired output file:
folder_path = r'YOUR_FOLDER_PATH_HERE'
output_file = 'combined.xlsx'For example:
folder_path = r'C:\Users\dylan\OneDrive\Documents\Sample_CSV_Data'
output_file = 'combined.xlsx'✅ Tip: Use r'path' for Windows paths to avoid escape character errors.
- Run the script:
Windows:
python csv_to_excel.py
macOS:
python3 csv_to_excel.py
- Generates an Excel workbook (
.xlsx) - Each sheet is named after the corresponding CSV file
- Saves to the same directory unless an absolute output path is provided
(Add your screenshots here for clarity in your portfolio)
- All CSV files must have a
.csvextension and valid headers. - The script uses pandas for reading CSVs and openpyxl as the Excel writer engine.
- You can change the output folder by specifying a different
output_filepath.
Dylan Cleal – Python Developer | Data Automation & Web Scraping Specialist

