I have an input file, in which I am making an string replace operation.
I read the file cell by cell, replace the string and then write it back to a new CSV file.
input_file = open('/Users/tcssig/Desktop/unstacked2.csv', 'r', encoding='utf-8')
output_file = open('/Users/tcssig/Desktop/unstacked3.csv', 'w', encoding='utf-8')
writer = csv.writer(output_file , delimiter=' ')
reader = csv.reader(input_file)
for row in reader:
for string in row:
data = [string.replace('read','write')]
print(data)
writer.writerow(data)
Above code runs well, but I get an empty output file.
Example of data :
reading reading reading reading
interval 0 1 2 3
who axis
Mikael X 0 10 20 30
Mikael Y 50 40 30 20
Mikael Z 100 90 80 70
Mike X 0 0.1 0.2 0.3
Mike Y 0.5 0.4 0.3 0.2
Mike Z 1 0.9 0.8 0.7
What am i missing?