Feb-11-2022, 12:35 AM
Hello,
The script generates output as 1 line for each record but I wanted to separate the output that looks like this. Your response is greatly appreciated. Thank you!
The script generates output as 1 line for each record but I wanted to separate the output that looks like this. Your response is greatly appreciated. Thank you!
Output:index
movie
genre year country
1
movie1
action 2020 USA
2
movie2
drama 2019 UK
etc...
import csv from datetime import date import glob from multiprocessing import Condition from re import A from tkinter import filedialog import pandas as pd header = ['index','movie','genre','year','country'] filename = 'dataFile.csv' inFileData = open(filename, 'r') rLines = inFileData.readlines() #process file later inFileData.close() #printing values in text file with open('outputFile.txt', 'w') as outFileText: outFileText.write('Total Records: ') outFileText.write(rLines[0]) #writes header file recordIndex = 1 for line in rLines[1:]: if recordIndex < 10: outFileText.write(line.replace(",", " ")) #REPLACE commas with whitespace recordIndex = recordIndex + 1 outFileText.close()
Attached Files