I have a set of text documents (basically they are emails saved as text files.) I have to read these and write in a CSV or Pandas data frame. Each row should take one email or text file. Something like below:
Filename Content
email_file1 content1
email_file2 content2
email_file3 content3
email_file4 content4
email_file5 content5
I am using this code:
import os
os.chdir('file path')
from pathlib import Path
with open('big.csv', 'w') as out_file:
csv_out = csv.writer(out_file)
csv_out.writerow(['FileName', 'Content'])
for fileName in Path('.').glob('*.txt'):
csv_out.writerow([str(fileName),open(str(fileName.absolute())).read().strip()])
However, I am getting the following output. The problem with this output is, I am getting a white space (a line gap between each row)
Filename Content
email_file1 content1
email_file2 content2
email_file3 content3
email_file4 content4
email_file5 content5
I am not sure why this is occurring and how to solve this. Please help.