import csv import os # Function to extract the first column from a CSV file 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 # Directory containing combo CSV files csv_directory = os.path.dirname(os.path.abspath(__file__)) # List to store the first columns from each CSV all_first_columns = [] # Loop through each combo CSV file for i in range(1, 7): # Assuming combo files are named combo1.csv to combo6.csv csv_file_path = os.path.join(csv_directory, f'text10combo{i}.csv') first_column = extract_first_column(csv_file_path) all_first_columns.append(first_column) # Transpose the list of lists to get a list of columns all_first_columns_transposed = list(map(list, zip(*all_first_columns))) # Save the transposed result into a new CSV file output_csv_path = os.path.join(csv_directory, 'loopnum10.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}")