try this: (with the below code you can read Book1.xlsx, convert the excel file to list of lists
, and write list of lists
in excel file(Book2.xlsx))
EDIT : I add start_cloumn
and start_row
as your request for set where start row
and column
for adding 0x
.
import pandas as pd
import xlsxwriter
df = pd.read_excel(r'Book1.xlsx')
lst = [df.columns.values.tolist()] + df.values.tolist()
start_cloumn = 4 # added this line on EDIT
start_row = 2 # added this line on EDIT
with xlsxwriter.Workbook('Book2.xlsx') as workbook:
worksheet = workbook.add_worksheet()
for row_num, data in enumerate(lst):
if row_num >= start_row:
data = ["0x" + str(d) if column_num >= (start_cloumn-1) else str(d) for column_num, d in enumerate(data)]
worksheet.write_row(row_num, 0, data)
output:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.