0

I want to read the data from the text file below and write it to an Excel sheet as explained further

enter image description here

The text file is formatted with each value on a new line.

The Excel file should have

  • 'adobe' in row 0, column 1
  • IE11.o to row 0, column 2
  • 32 to row 0, column 3

  • flash to row 1, column 1

  • IE8.0 to row 1, column 2
  • 24 to row 1, column 3

and so on for many rows

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
san
  • 81
  • 1
  • 1
  • 8

1 Answers1

0

You probably want to read the text file, line by line, into a list. Then you can either export your data as a .csv file which excel can read, or directly as an excel file using a library like Openpyxl.

For example this code does what you've asked for, if you're happy to produce a .csv instead of an excel file:

fname = "" #path to file
csvname = "" #path to output csv

with open(fname) as f: #reads the file
    content = f.readlines() #writes lines to list
content = [x.strip() for x in content] #removes blank list values

names = content[0::3] #builds list of names
IEs = content[1::3] #builds list of IEs
numbers = content[2::3] #builds list of numbers

with open(csvname) as file: #creates csv file
    for i in range(len(content)/3): #runs through rows
        file.write(names[i]+","+IEs[i]+","+numbers[i]) #writing data to rows
        file.write('\n') #ends line after each row
Community
  • 1
  • 1
Ari Cooper-Davis
  • 3,374
  • 3
  • 26
  • 43