I wrote some code and trying to refactor it to cut out a few steps and i cant seem to find an answer for this. Im reading an excel file and doing a bunch of column renaming and dropping columns i dont need. My end goal is to write the Excel file as an text tab delimited file and accomplished all this but in a very hacky way. I have a function convertToText() that reads the excel file and turns it into a txt file. However every single integer in the file gets a .0 appended to the end.
Ex.
Excel value 1234321
Txt File = 1234321.0
Im just doing a simple read and write using pandas, openpyxl and xlrd.
def convertToText():
with open(os.path.join(outFile, 'target2.txt'), 'wb') as myTxtfile:
wr = csv.writer(myTxtfile, delimiter="\t")
myfile = xlrd.open_workbook(outFile + fileName)
mysheet = myfile.sheet_by_index(0)
for rownum in xrange(mysheet.nrows):
wr.writerow(mysheet.row_values(rownum))
I had to write a second function just to do a find and replace on the .0 and trying to cut that step out of the process. If anyone has any ideas how to do this in the above function would be greatly appreciated!!