Reputation: 432
Trying to do some data analysis on some data but all downloaded data is in .tbl format and I would rather have it in .csv format. Is there a way to convert to .tbl to .csv through a python script.
Right now, I am uploading the files directly into excel which does the job but I need this process to be a bit quicker
Upvotes: 1
Views: 3575
Reputation: 131
Hope this code snippet will help you.
def converttbldatatocsvformat(filename, header):
csv = open("".join([path, filename, ".csv"]), "w+")
csv.write(header + "\n")
tbl = open("".join([path, filename, ".tbl"]), "r")
lines = tbl.readlines()
for line in lines:
length = len(line)
line = line[:length - 2] + line[length-1:]
line = line.replace(",","N")
line = line.replace("|",",")
csv.write(line)
tbl.close()
csv.close()
Upvotes: 1