Last active
July 14, 2023 02:45
-
-
Save wikytam/c1073eac1a4e92379075b7dfee4b4200 to your computer and use it in GitHub Desktop.
Merge CSV file using Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import pandas as pd | |
| if __name__ == '__main__': | |
| csv_files = [file for file in os.listdir('excel') if file.endswith('.csv')] | |
| dfs = [] | |
| for file in csv_files: | |
| file_path = os.path.join('excel', file) | |
| df = pd.read_csv(file_path) | |
| dfs.append(df) | |
| merged_df = pd.concat(dfs, axis=0, join='outer', ignore_index=True, keys=None, levels=None, names=None, | |
| verify_integrity=False, copy=True) | |
| merged_df.to_csv('merged_file.csv', index=False) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Merge xlsx file using Python
Requirements:
The script requires that all input Excel files (.xlsx) be located in a folder named excel.
The output file should be named output_file.xlsx.
The script will merge all worksheets with the same name across all input Excel files into a single worksheet in the output file.