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...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
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