import xlsxwriter as writer
Note: xlsxwriter can only create new files, not modify existing files. If a new file is created with the same name as the original file, the original file will be overwritten.
import xlsxwriter as writer workbook = writer.Workbook('stock_industry_result.xlsx') worksheet = workbook.add_worksheet() #Add a sheet
worksheet.write(0, 0, "Span of important time points") #Set the title of the first row
worksheet.write(0, 1, "Average duration")
for i in range (number_of_dates-1): #Write data
worksheet.write(i+1, 0, important_dates_time[i]+"--"+important_dates_time[i+1])
worksheet.write(i+1, 1, ave_timelength[i ])
workbook.close()
There are also operations for reading and writing excel under pandas:
import pandas as pd shuju = pd.read_excel( " Convertible bond pricing parameter table 0117.xlsx " ) a, b = shuju.shape # a is the number of rows after removing the title b is the actual number of columns, shuju[ " Coupon Rate " ] = Piaoxilv #Add a new column shuju.to_excel( " shuju_new.xlsx " ) #Write to in excel