python - Two columns of data need to be saved as an excel file -
i have 2 columns of data, x , y values, , need save file excel file opened in excel. there modules can me this?
the format needs xls
the data looks follows:
4.20985 17.1047 4.82755 16.4046 3.17238 12.1246 4.50796 18.0955 6.04241 21.1016 4.62863 16.4974 4.32245 14.6536 6.48382 19.7664 5.66514 20.1288 6.11072 22.6859 5.55167 15.7504
it looks you'd creating csv
file, since you've asked xls
, here's example using xlwt module:
import xlwt data = """ 4.20985 17.1047 4.82755 16.4046 3.17238 12.1246 4.50796 18.0955 6.04241 21.1016 4.62863 16.4974 4.32245 14.6536 6.48382 19.7664 5.66514 20.1288 6.11072 22.6859 5.55167 15.7504 """ # prepare two-dimensional list data = [map(float, item.split()) item in data.split('\n') if item] # create workbook , add sheet workbook = xlwt.workbook() sheet = workbook.add_sheet('test') # loop on two-dimensional list , write data index, (value1, value2) in enumerate(data): sheet.write(index, 0, value1) sheet.write(index, 1, value2) # save workbook workbook.save('test.xls')
hope helps.
Comments
Post a Comment