Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import csv
# Paths to your CSV files
csv_file_path1 = 'output_1.csv'
csv_file_path2 = 'testout.csv'
csv_file_path3 = 'category.csv'
csv_file_path4 = 'idk.csv'
names = []
# Open the CSV file and read each row
with open(csv_file_path3, mode='r', encoding='utf-8') as file:
reader = csv.reader(file)
for row in reader:
# Assuming names are in the first column
names.append(row[1])
print(names)
i = 0
# Open both files
combined_rows = []
with open(csv_file_path1, 'r') as file1, open(csv_file_path2, 'r') as file2, open(csv_file_path4, 'w', encoding='utf-8') as file4:
# Create csv.reader objects
reader1 = csv.reader(file1)
reader2 = csv.reader(file2)
writer = csv.writer(file4)
# Iterate over both files simultaneously
for row1, row2 in zip(reader1, reader2):
print(i)
print(row2, row1)
i += 1
if i > 4880:
if row1[1] != row2[1]:
if row1[1] != 'error' and row2[1] == "error":
#replace row2[1] with row1[1]
combined_rows.append(row1)
# If the rows are not the same, print them (or handle as needed)
print(f"Difference:\nFile 1: {row1}\nFile 2: {row2}")
elif row2[1] not in names and row1[1] in names:
combined_rows.append(row1)
else:
combined_rows.append(row2)
else:
combined_rows.append(row2)
with open(csv_file_path4, 'w', newline='') as file4:
writer = csv.writer(file4)
writer.writerows(combined_rows)