excel - Read CSV without string formatting in python -
i have csv file , read cell-by-cell can write excel. using csv.reader , enumerating result can set values corresponding cells in excel.
with current code, 1 time enumerate values turn strings. if write excel sheet.write(rowi,coli,value), cells formatted text. can't have this, because need sum columns afterward , need treated numbers
for example, text file have: 1, a, 3, 4.0, 5, 6, 7
after first enumeration, first row: (0, '1, a, 3, 4.0, 5, 6, 7')
after sec enumeration, first column of first row: (0, 0, '1')
question: how can read csv file yield (0, 0, 1) (etc.)?
here's code i'm working with:
import csv, xlwt open('file.csv', 'rb') csvfile: info = csv.reader ((csvfile), delimiter=",") wbk= xlwt.workbook() sheet = wbk.add_sheet("file") rowi, row in enumerate(data): coli, value in enumerate(row): sheet.write(rowi,coli,value) #print(rowi,coli,value) gives (rowi, coli, 'value') import csv, xlwt open('file.csv', 'rb') csvfile: info = csv.reader ((csvfile), delimiter=",") wbk= xlwt.workbook() sheet = wbk.add_sheet("file") rowi, row in enumerate(data): coli, value in enumerate(row): sheet.write(rowi,coli,value) wbk.save("workbook_file")
even though print(rowi,coli,value) shows 'value', cell in outputted file should show without quotes.
if info in format 1, 2, 3 , not 1,2,3 include after for coli, value in enumerate(row): line:
value = value.lstrip(" ")
python excel csv
No comments:
Post a Comment