I want to convert this file.tsv to csv the conversion works well but the seperation of the fields isn't this is the file.tsv
protein1 protein2 neighborhood neighborhood_transferred fusion cooccurence homology coexpression coexpression_transferred experiments experiments_transferred database database_transferred textmining textmining_transferred combined_score
9606.ENSP00000003084 9606.ENSP00000301645 0 0 0 0 0 0 0 0 0 0 0 163 129 239
here is the first line result file.csv
"protein1 protein2 neighborhood neighborhood_transferred fusion cooccurence homology coexpression coexpression_transferred experiments experiments_transferred database database_transferred textmining textmining_transferred combined_score"
"9606.ENSP00000003084 9606.ENSP00000301645 0 0 0 0 0 0 0 0 0 0 0 163 129 239"
Here is the code
import csv
print(csv.list_dialects())
with open('File.tsv', 'r', encoding='utf-8', newline='') as fin, \
open('file2.csv', 'w', encoding='utf-8', newline='') as fout:
reader = csv.reader(fin, dialect='excel-tab')
writer = csv.writer(fout, delimiter=' ')
for row in reader:
writer.writerow(row)
The problem is that the code don't seperate the fields using the space, it taked the whole header for one row
The desired result is that the seperation should be where I put commas
protein1,protein2,neighborhood,neighborhood_transferred,fusion,cooccurence homology,coexpression,coexpression_transferred,experiments experiments_transferred,database,database_transferred,textmining, textmining_transferred,combined_score
9606.ENSP00000003084,9606.ENSP00000301645,0,0,0,0,0,0,0,0,0,0,0,163,129,239