Hello,
I need your help with the below please ๐
I have TWO ".CSV" files with the same number of columns and rows (257 columns and X rows). I want to merge them together as follows;
Write the content of the first (256 columns) from the first file, then write the content of the second file.
I have written below code, but I'm ending up with a loop that creates a huge size huge that crashes my computer every time! Although, when testing with a smaller size CSV files, I'm getting a good result.
I need your help with the below please ๐
I have TWO ".CSV" files with the same number of columns and rows (257 columns and X rows). I want to merge them together as follows;
Write the content of the first (256 columns) from the first file, then write the content of the second file.
I have written below code, but I'm ending up with a loop that creates a huge size huge that crashes my computer every time! Although, when testing with a smaller size CSV files, I'm getting a good result.
# This is a sample Python script.
import csv
# read data from file1.csv and file.csv
file1 = open('./File1.csv')
file2 = open('./File2.csv')
# make csv readers object for each file
reader1 = csv.reader(file1)
reader2 = csv.reader(file2)
# write a result to result.csv
file3 = open('./Result.csv', 'w')
writer = csv.writer(file3)
dic = {}
words = []
# read data from file1
for row in reader1:
count = len(row)
words.append(row[count - 1])
dic[row[count - 1]] = row[0:count - 1]
# read data from file2 and merge data with file1
for row in reader2:
count = len(row)
dic[row[count - 1]] += row[0:count - 1]
#write data to result.csv
for word in words:
dic[word].append(word)
writer.writerow(dic[word])
print('merge finished')

![[Image: 26396346ff660680ae25089130fa60b3dcd68f55...3e0941.jpg]](https://serving.photos.photobox.com/26396346ff660680ae25089130fa60b3dcd68f55f9c5ed451c141b8eb59d531ea43e0941.jpg)