Good New Year to you all, there is a table in the end of the original data added statistical data, the code after the operation found that the first column of the original data (order number) is modified to 0 and columns within the data deleted, how do I after adding in the end of the original data statistics, the original data remains the same, the code is as follows:
The from openpyxl import load_workbook
The import pandas as pd
The import numpy as np
Df=pd read_excel (" the order form. XLSX, sheet_name='sheet1', engine='openpyxl')
The book=load_workbook (" the order form. XLSX ")
Writer=pd. ExcelWriter (" the order form. XLSX, "engine='openpyxl')
Writer.=the book book
Writer. Sheets=dict ((ws. The title, ws) for ws in the book. Worksheets)
Total number of order #
Data1=df [' order number]. The count ()
# revenue total amount (RMB)
Data2=np. Sum (df [' actual price paid '])
Stotal1=[" total order: ", data1, revenue total amount (RMB) : "", data2,]
Df=df append (stotal1)
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. The save ()