import xlsxwriter as writer
注意: xlsxwriter 只能创建新文件,不可以修改原有文件。如果创建新文件时与原有文件同名,则会覆盖原有文件.
import xlsxwriter as writer workbook = writer.Workbook('stock_industry_result.xlsx') worksheet = workbook.add_worksheet() #添加一个sheet
worksheet.write(0, 0, "重要时点跨度") #设置第一行的标题
worksheet.write(0, 1, "平均时长")
for i in range(number_of_dates-1): #写入数据
worksheet.write(i+1, 0, important_dates_time[i]+"--"+important_dates_time[i+1])
worksheet.write(i+1, 1, ave_timelength[i])
workbook.close()
pandas下面也有读取excel 与写入excel的操作:
import pandas as pd shuju = pd.read_excel("转债定价参数表0117.xlsx") a, b = shuju.shape #a为除去标题之后的行数b是实际列数, shuju["票息率"] = Piaoxilv #新增一列 shuju.to_excel("shuju_new.xlsx") #写入到excel中