-
Notifications
You must be signed in to change notification settings - Fork 1
/
combine.py
29 lines (22 loc) · 862 Bytes
/
combine.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import csv
import os
folder_path = os.getcwd()
csv_files = [file for file in os.listdir(folder_path) if file.endswith('.csv')]
def combine_csv_files(output_file):
unique_records = []
for file in csv_files:
with open(file, mode='r', encoding='utf-8-sig') as f:
reader = csv.reader(f)
next(reader)
for row in reader:
if row not in unique_records:
unique_records.append(row)
# Write unique records to the output file
with open(output_file, 'w', encoding='utf-8-sig', newline='') as file:
writer = csv.writer(file)
# Write headers
headers = ['Date', 'Time', 'Author', 'Msg']
writer.writerow(headers)
for msg in unique_records:
writer.writerow(msg)
combine_csv_files("combined.csv")