|
import csv |
|
import os |
|
|
|
|
|
def extract_first_column(csv_file): |
|
with open(csv_file, 'r') as file: |
|
reader = csv.reader(file) |
|
first_column = [int(row[0]) for row in reader] |
|
return first_column |
|
|
|
|
|
csv_directory = os.path.dirname(os.path.abspath(__file__)) |
|
|
|
|
|
all_first_columns = [] |
|
|
|
|
|
for i in range(1, 7): |
|
csv_file_path = os.path.join(csv_directory, f'text3combo{i}.csv') |
|
first_column = extract_first_column(csv_file_path) |
|
all_first_columns.append(first_column) |
|
|
|
|
|
all_first_columns_transposed = list(map(list, zip(*all_first_columns))) |
|
|
|
|
|
output_csv_path = os.path.join(csv_directory, 'loopnum3.csv') |
|
with open(output_csv_path, 'w', newline='') as csvfile: |
|
writer = csv.writer(csvfile) |
|
writer.writerows(all_first_columns_transposed) |
|
|
|
print(f"Combined first columns saved to {output_csv_path}") |
|
|