I am writing a code that converts .txt file to .xls file and I need for every 4th column of my .txt file to go into, say "Sheet 1" and every third file to go in, say "Sheet 2" and so forth. The text file has headers in the first 2 rows, and the actual data starts in the 3rd column. I am not sure how do this and any guidance or help would be very appreciated. Here is my current code:
import xlwt
import six
import itertools
def is_number():
try:
float(s)
return True
except ValueError:
return False
def txt_to_xls():
f=open('textfile.txt', 'r+')
row_list=[]
for row in f:
row_list.append(row.split())
column_list=map(list, siz.moves.zip_longest(*row_list, fillvalue=' '))
workbook=xlwt.Workbook()
worksheet=workbook.add_sheet('Sheet 1')
i=0
for column in column_list:
for item in range(len(column)):
value=column[item].strip()
if is_number(value):
worksheet.write(item, i, float(value))
else:
worksheet.write(item, i, value)
i+=1
workbook.save('test.xls')