, ladies and gentlemen, there is a table (sheet1) because of the variable amount of data (that is, the number of rows), want to automatically add a line in the end of the data in the table as "total order:", "revenue total amount (RMB) :", "orders: total failure", the content of the "total number of treatment success", to consult and implementation?
The code is as follows:
The from openpyxl import load_workbook
The import pandas as pd
The import numpy as np
The from openpyxl. Utils. Dataframe import dataframe_to_rows
# write data
Data1=df [' order number]. The count ()
Data2=np. Sum (df [' actual price paid '])
Data3=np. Sum (([df [' order status']=='has a refund'], [df [' order status']=='failures']]))
Data4=np. Sum (([df [' order status']=='treatment success']))
Datatotal1=pd. DataFrame ([" total order: ", "revenue total amount (RMB) :", "orders: total failure", "total treatment success"])
Df. Loc [0]=[data1, data2, data3, respectively, data4]
Df. To_excel (writer, sheet_name='sheet1', startcol=0, while the startrow=0, the index=False, the header=True)
Wbsheet=the book [' sheet1]
Namelist='sheet1'
writer.save()